Skip to content
Advertisement

JSON string from a ‘kind’ of JSON string that needs to be evaled

I have a string (str_json) that I’m getting from elsewhere :

JavaScript

This is a string str_json which is supposed to be JSON but it actually contains some python code and a number value and single quotes.

json.loads will fail.

What I need is the JSON string of str_json.

json_data = json.loads(str_json)

What I’ve attempted so far :

JavaScript

Advertisement

Answer

You can handle that datetime thingy like this, which converts the datetime into proper json:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement