Skip to content
/ pyjsonfix Public

Does its best to turn Javascript object literals into valid JSON.

Notifications You must be signed in to change notification settings

pl77/pyjsonfix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

pyjsonfix

pyjsonfix tries to "fix" broken JSON.

JSON is actually a subset of JavaScript object literals. And more often than not, it isn't valid JSON. If you want to use the json module, it's not going to work. That's where pyjsonfix is useful. It'll try to coax it into a useable form.

Please note, it hasn't been extensively tested, so I don't know what it'll break on. It's been pretty good with what I've come across.

Example

bad_json = """{'ca"ke': 5.05, pie:[0,0xb,,2,{foo:"fo\\43ob",bar:'barb'}], 
	null:null, false:true, ' ':true, "'":false, 010: 4,  l3l :  10  }"""

from jsonfix import fixJSON

fixed_json = fixJSON(bad_json)
print fixed_json
# {"ca\"ke": 5.05, "pie":[0,11,null,2,{"foo":"fo\u0023ob","bar":"barb"}], 
#     "null":null, "false":true, " ":true, "'":false, "8": 4,  "l3l":  10  }

import json
from pprint import pprint
pprint(json.loads(fixed_json))
# {u' ': True,
# u"'": False,
# u'8': 4,
# u'ca"ke': 5.05,
# u'false': True,
# u'l3l': 10,
# u'null': None,
# u'pie': [0, 11, None, 2, {u'bar': u'barb', u'foo': u'fo#ob'}]}

About

Does its best to turn Javascript object literals into valid JSON.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages