Content-Length: 305650 | pFad | http://github.com/rhgrant10/ndjson

4A GitHub - rhgrant10/ndjson: ndjson with the same interface as the builtin json module
Skip to content

ndjson with the same interface as the builtin json module

License

Notifications You must be signed in to change notification settings

rhgrant10/ndjson

Repository files navigation

ndjson

Support for ndjson. Plain and simple.

https://img.shields.io/pypi/pyversions/ndjson https://img.shields.io/pypi/l/ndjson

Features

  • familiar interface
  • very small
  • no dependencies
  • works as advertised
  • has tests

Usage

ndjson exposes the same api as the builtin json and pickle packages.

import ndjson

# load from file-like objects
with open('data.ndjson') as f:
    data = ndjson.load(f)

# convert to and from objects
text = ndjson.dumps(data)
data = ndjson.loads(text)

# dump to file-like objects
with open('backup.ndjson', 'w') as f:
    ndjson.dump(items, f)

It contains JSONEncoder and JSONDecoder classes for easy use with other libraries, such as requests:

import ndjson
import requests

response = requests.get('https://example.com/api/data')
items = response.json(cls=ndjson.Decoder)

The library also packs reader and writer classes very similar to standard csv ones:

import ndjson

# Streaming lines from ndjson file:
with open('./posts.ndjson') as f:
    reader = ndjson.reader(f)

    for post in reader:
        print(post)

# Writing items to a ndjson file
with open('./posts.ndjson', 'w') as f:
    writer = ndjson.writer(f, ensure_ascii=False)

    for post in posts:
        writer.writerow(post)

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

About

ndjson with the same interface as the builtin json module

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/rhgrant10/ndjson

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy