Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

JsonDecoder for ndjson

Project description


Support for ndjson. Plain and simple.


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


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('')
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:

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

    for post in posts:


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


0.3.1 (2020-02-24)

  • Fix a small spelling mistake

0.3.0 (2020-02-24)

  • Add ndjson.writer
  • Add ndjson.reader

0.2.0 (2019-08-01)

  • Add 3.7 support
  • Remove 3.4 support

0.1.0 (2018-05-17)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ndjson, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size ndjson-0.3.1-py2.py3-none-any.whl (5.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size ndjson-0.3.1.tar.gz (6.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page