A
A
Andrey2019-06-27 22:43:16
Python
Andrey, 2019-06-27 22:43:16

Why can't convert json to dictionary?

There is this Vkontakte API response:

spoiler
{"response":{"count":1011,"items":[{"conversation":{"peer":{"id":-183235386,"type":"group","local_id":183235386},"in_read":1131663,"out_read":1131663,"last_message_id":1131663,"can_write":{"allowed":true},"current_keyboard":{"one_time":true,"author_id":-183235386,"buttons":},"can_send_money":true,"can_receive_money":false},"last_message":{"date":1561632212,"from_id":-183235386,"id":1131663,"out":0,"peer_id":-183235386,"text":"Очень жаль! Скажите, пожалуйста, почему Вы передумали?","conversation_message_id":29,"fwd_messages":[],"keyboard":{"one_time":true,"author_id":-183235386,"buttons":},"important":false,"random_id":0,"attachments":[],"is_hidden":false}}],"groups":[{"id":183235386,"name":"Бот пожертвований (пример)","screen_name":"donatebot","is_closed":0,"type":"page","is_admin":0,"is_member":0,"is_advertiser":0,"photo_50":"https:\/\/sun1-16.userapi.com\/c849324\/v849324326\/1b1da0\/6XC_EioXAW4.jpg?ava=1","photo_100":"https:\/\/sun1-14.userapi.com\/c849324\/v849324326\/1b1d9f\/dhXXJXl_S8U.jpg?ava=1","photo_200":"https:\/\/sun1-84.userapi.com\/c849324\/v849324326\/1b1d9e\/iGvySBJBBEo.jpg?ava=1"}]}}
When trying to json.loads(str) gives JSONDecodeError: Expecting ',' delimiter
At the same time, there were never any problems with the received information about other messages, only with this particular message/community there was a problem.
Z.Y. Please not only show where the error is, but also write ways to find it for long lines, in which it is almost impossible to find it "by a close look"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Yakushenko, 2019-06-27
Kastelin @Vertonger

This is already decoded json, you don't need to do it again, just refer to it, for example:

response.get('response').get('count')
# или
response['response']['count']

S
Stalker_RED, 2019-06-27
@Stalker_RED

ways to find it for long strings, in which it is almost impossible to find it by the "gaze method"
https://www.google.com/search?q=json+validator
or any editor with syntax highlighting.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question