-1

I am reciving this dictionary object from a react native client. i am using django rest framework as back end. i was to parse the values of pushToken and user object in my django backend.

Here is the object,

{
  'pushToken': { 'type': 'expo', 'data': 'ExponentPushToken[OQ927mOVsi3_j2e]' },
  'user': '{"token":"78d7fa3e903b61ac14c0119c9676b24512","user_id":3,"username":"vitor","email":"vitor@reactnative.com"}',
}

So far i have tried to covert in into json object using json.dump()... But it did not works

Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
  • 1
    Does this answer your question? [Converting dictionary to JSON](https://stackoverflow.com/questions/26745519/converting-dictionary-to-json) – ashishmishra Sep 15 '21 at 12:12

2 Answers2

0

Have you try to copy it? Here is what I got from JSON formatter,

{
   "pushToken":{
      "type":"expo",
      "data":"ExponentPushToken[OQ927mOVsi3_j2e]"
   },
   "user":"{\"token\":\"78d7fa3e903b61ac14c0119c9676b24512\",\"user_id\":3,\"username\":\"vitor\",\"email\":\"vitor@reactnative.com\"}"
}

Try to validate your JSON first then you can dump it.

rcanpahali
  • 2,565
  • 2
  • 21
  • 37
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 15 '21 at 13:27
0

json.dumps() will convert the dict object to string in order to send via an API, alternatively json.loads() is used to load a JSON string into a dictionary.

json.dump() is a different command where it will ask for a filename where you want to store this JSON.

If it is already a dictionary, try accessing the key-value pairs.

for example say d = {'pushToken': {'type': 'expo', 'data': 'ExponentPushToken[OQ927mOVsi3_j2e]'}, 'user': '{"token":"78d7fa3e903b61ac14c0119c9676b24512","user_id":3,"username":"vitor","email":"vitor@reactnative.com"}'}

d['pushToken']['type'] will give 'expo'

Agnij
  • 561
  • 3
  • 13