jsonlike

repair and parse invalid but jsonlike content


License
MIT
Install
pip install jsonlike==0.0.2

Documentation

jsonlike Build Status PyPI version

Why?

Sometimes, especially when working with JSON data from the web, you will find that the data format is not quite JSON and thus have to do a little bit of fighting with it in order to successfully call json.loads().

Goal

The goal of this package is try and provide the same functionality as json.loads() for data that looks like JSON, but doesn't play nicely with json.loads() or other common solutions.

In its current state, it simply applies some heuristics that solve some of the common cases I've run into while working with not-quite json structured data. Overtime, I'd like to see it turn into something a bit more robust.

Usage

import jsonlike
jsonlike.loads(invalid_json_string)

Currently, jsonlike.loads will

  • strip out bad escape characters
  • strip out HTML content with JSON values
  • add missing commas
  • correct errors due to nested "'s
Strip response callback wrappers
import jsonlike
jsonlike.unwrap_and_load("callback({"a": ""hello""})") # yields {"a":"hello"}

For JSON surrounded by a callback wrapper, calling unwrap_and_load will use the unwrapper library to strip away the callback, before returning loads() on the remaining content.

Installation

$ pip install jsonlike

Contributing

  1. Fork it ( https://github.com/shaunvxc/jsonlike/fork )
  2. Create your feature branch (git checkout -b new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Run the tests (make test)
  5. Push change to the branch (git push origin new-feature)
  6. Create a Pull Request