python: parse json with unquoted keys common in js

First of all, it should be clear that in the json standard, the key must be quoted, so the standard json module will throw an error when parsing the json without the quoted key

But there are some libs that can help us parse

eg: demjson ( link )

>>>> import demjson
>>> demjson.decode('{suggestion:[{query:"London",interpretation: ...')
{u'suggestion': [{u'query': u'London', u'operation': 2, u'interpretation': ...

 

Simple example (code)

>>> import demjson

>>> demjson.encode( ['one',42,True,None] )    # From Python to JSON
'["one",42,true,null]'

>>> demjson.decode( '["one",42,true,null]' )  # From JSON to Python
['one', 42, True, None]

>>> cfg = demjson.decode_file( "config.json" )  # Read JSON from a file

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325148808&siteId=291194637