P
P
pruha192018-12-10 16:58:30
Python
pruha19, 2018-12-10 16:58:30

How to work with json schema, where there are variable values ​​true and false?

{  
   "type":"sq_question_answers_right",
   "owner_id":-162894513,
   "video_id":456230000,
   "question":{  
      "text":"Кто основал социальную сеть ВКонтакте?",
      "answers":[  
         {  
            "id":0,
            "text":"Николай Дуров",
            "users_answered":1584
         },
         {  
            "id":1,
            "text":"Павел Дуров",
            "users_answered":389217
         },
         {  
            "id":2,
            "text":"Илон Маск",
            "users_answered":389
         }
      ],
      "right_answer_id":1,
      "id":11,
      "is_first":true,
      "is_last":false,
      "number":1,
      "sent_time":1529600002,
      "answer_set":true
   },
   "question_time":1529600000,
   "version":2
}

Let's take this line as an example, several variables are set to true or false, on which python will throw an error. How to solve the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Emil Revencu, 2018-12-10
@Revencu

can run the line first through:

json_obj=json.loads(json_string.replace('true','True').replace('false','False'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question