JSON Helpers
Project description
jsonio
The jsonio
package provides utility functions for reading and writing JSON data. It supports the following features:
- Easy Read/Write
- Works Just Like The
json
Library - Supports
datetime/date
Objects - Supports
dataclasses
(Python 3.7+) - Preserve Ordering
Installation
pip install jsonio
Easy Read/Write
Read
import jsonio
data = jsonio.read('/foo/bar.json')
Write
import jsonio
jsonio.write({'foo': 'bar'}, '/foo/bar.json')
Works Just Like The json
Library
Load
import jsonio
with open('/foo/bar.json', 'r') as jsonfile:
data = jsonio.load(jsonfile)
Loads
import jsonio
data = jsonio.loads('{"foo": "bar"}')
Dump
import jsonio
with open('/foo/bar.json', 'w') as jsonfile:
jsonio.dump({'foo': 'bar'}, jsonfile)
Dumps
import jsonio
data = {
'apple': 'crumble',
'banana': 'split',
}
# Use standard options.
text = jsonio.dumps(data, jsonfile, indent=2, sort_keys=True)
Supports date/datetime
Objects
import datetime
import jsonio
before = {
'date': datetime.date.today(),
'timestamp': datetime.datetime.now(),
}
jsonio.write(before, '/foo/bar.json')
after = jsonio.read('/foo/bar.json')
assert before == after # True
Supports dataclasses
(Python 3.7+)
from dataclasses import dataclass
import jsonio
@dataclass
class Fruit:
apple: str
banana: str
before = Fruit(apple='Fuji', banana='Lady Finger')
jsonio.write(before, '/foo/bar.json')
after = jsonio.read('/foo/bar.json')
assert before == after # True
Preserve Ordering - i.e. OrderedDict
Objects
import collections
import jsonio
before = collections.OrderedDict([('banana', 'split'), ('apple', 'crumble')])
text = jsonio.dumps(before, indent=2)
after = jsonio.loads(text, ordered=True)
assert before == after # True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsonio-0.1.3.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for jsonio-0.1.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82601053e3b5e9e9a9387769b34dff82f15711185973a5d8d3d610fe2a4f197b |
|
MD5 | 4b65e0e3e575fbf02774323dc8fdedaa |
|
BLAKE2b-256 | dd33e6f75c2d599a36ca3e1d1db57c54678884130a513f7849988bacb9830261 |