https://github.com/hjson/hjson-py
Hjson for Python
https://github.com/hjson/hjson-py
hjson python
Last synced: 6 months ago
JSON representation
Hjson for Python
- Host: GitHub
- URL: https://github.com/hjson/hjson-py
- Owner: hjson
- License: other
- Created: 2015-01-05T15:12:08.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-08-13T02:43:16.000Z (about 3 years ago)
- Last Synced: 2025-04-01T15:11:55.724Z (6 months ago)
- Topics: hjson, python
- Language: Python
- Homepage: https://hjson.github.io/
- Size: 1.14 MB
- Stars: 214
- Watchers: 10
- Forks: 19
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: history.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# hjson-py
[](http://travis-ci.org/hjson/hjson-py)
[](https://pypi.python.org/pypi/hjson)[Hjson](https://hjson.github.io), a user interface for JSON

Hjson works with Python 2.5+ and Python 3.3+
The Python implementation of Hjson is based on [simplejson](https://github.com/simplejson/simplejson). For other platforms see [hjson.github.io](https://hjson.github.io).
# Installation
- `pip install hjson`
- or download from https://pypi.python.org/pypi/hjson
pip will also add the `hjson` tool to your `PATH` (try `echo '{a:1}'|hjson`).
## Commandline
```
Usage:
hjson [options]
hjson [options]
hjson (-h | --help)
hjson (-V | --version)Options:
-h --help Show this screen.
-j Output as formatted JSON.
-c Output as JSON.
-V --version Show version.
```E.g. `echo '{"json":"obj"}' | hjson`
# Usage
```python
import hjson
```## Decoding Hjson
```python
text = """{
foo: a
bar: 1
}"""hjson.loads(text)
```Result:
```python
OrderedDict([('foo', 'a'), ('bar', 1)])
```## Encoding Python object hierarchies
```python
hjson.dumps({'foo': 'text', 'bar': (1, 2)})
```Result:
```
{
foo: text
bar:
[
1
2
]
}
```## Encoding as JSON
Note that this is probably not as performant as the simplejson version.
```python
hjson.dumpsJSON(['foo', {'bar': ('baz', None, 1.0, 2)}])
```Result:
`'["foo", {"bar": ["baz", null, 1.0, 2]}]'`# API
[hjson-py documentation](http://hjson.github.io/hjson-py/)
# History
[see history.md](history.md)