https://github.com/slavfox/jsom
A fast, simple parser for terribly broken JSON
https://github.com/slavfox/jsom
dirty-json json json-parser python python37 wtfpl
Last synced: 11 months ago
JSON representation
A fast, simple parser for terribly broken JSON
- Host: GitHub
- URL: https://github.com/slavfox/jsom
- Owner: slavfox
- License: wtfpl
- Created: 2019-01-28T20:54:08.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-30T08:35:25.000Z (about 7 years ago)
- Last Synced: 2024-11-10T11:39:35.253Z (over 1 year ago)
- Topics: dirty-json, json, json-parser, python, python37, wtfpl
- Language: Python
- Homepage: https://pypi.org/project/jsom/
- Size: 14.6 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# JSOM - not quite JSON, but close enough
   
`jsom` is a simple and quick Python 3.7+ parser for terribly broken JSON.
## Installation
`$ pip install jsom`
## Usage
`jsom` works like this:
```python
>>> import jsom
>>> broken_json = "{\"foo\": {bar: 1, 'baz':,}, bar: 1, baz: [1,2,3,],}")
>>> jsom.JsomParser(ignore_warnings=jsom.ALL_WARNINGS).loads(broken_json)
{'foo': {'bar': 1, 'baz': None}, 'bar': 1, 'baz': [1, 2, 3]}
```
`jsom` happily gobbles up the following:
* unquoted keys and values
* single-quoted strings
* trailing commas
* empty values in objects
By default, it will warn you whenever it sees one of those, but still parse it.
It also doesn't give a shit about:
* Newlines in strings
* Stray backslashes
You will never get warned about those. ¯\\\_(ツ)\_/¯
Warnings are annoying, though, and to make matters worse, they slow the
parser down - so just pass in the list of warnings you want `jsom` to be quiet
about in the `ignore_warnings` parameter:
```
parser = JsomParser(
ignore_warnings=[jsom.SINGLE_QUOTED_STRING, jsom.EMPTY_OBJECT_VALUE]
)
```
Or, if you prefer, just tell it to shut up completely, by passing in
`jsom.ALL_WARNINGS`.
## LICENSE
`jsom` is distributed under the terms of the **Do What The Fuck You Want To
Public License (WTFPL)**:
```
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
```