Convert from undefined value in json file to string?

Viewed 42

I have a JSON file where I have an undefined value of key with a string as shown below:

{
                "display_url" : "bit.ly/1Thojq6",
                "indices" : [ 
                    90, 
                    113
                ]
            }
        ],
        "user_mentions" : [],
        "symbols" : [],
        "media" : [ 
            {
                "id" : NumberLong(715690140442734594),
                "id_str" : "715690140442734594",
                "indices" : [ 
                    114, 
                    137
                ],

The numbers with the Numberlong do not make it not valid JSON file, So I would like to change it to

 {
                "id" : "NumberLong(715690140442734594)",
                "id_str" : "715690140442734594",
                "indices" : [ 
                    114, 
                    137
                ],
1 Answers

try this :

json_object["media"][0]["id"] = "NumberLong(715690140442734594)"
a_file = open("your_file.json", "w")
json.dump(json_object, a_file)
a_file.close()
Related