Skip to main content

Ijson is a Python wrapper to YAJL which is a streaming SAX-like JSON parser. Ijson provides a standard Python iterator interface for it.

Usage

All usage example will be using a JSON document describing geographical objects:

{
  "earth": {
    "europe": [
      {"name": "Paris", "type": "city", "info": { ... }},
      {"name": "Thames", "type": "river", "info": { ... }},
      // ...
    ],
    "america": [
      {"name": "Texas", "type": "state", "info": { ... }},
      // ...
    ]
  }
}

Most common usage is having ijson yield native Python objects out of a JSON stream located under a prefix. Here’s how to process all European cities:

from ijson import items

f = urlopen('http://.../')
objects = items(f, 'earth.europe.item')
cities = (o for o in objects if o['type'] == 'city')
for city in cities:
    do_something_with(city)

Sometimes when dealing with a particularly large JSON payload it may worth to not even construct individual Python objects and react on individual events immediately producing some result:

from ijson import parse

f = urlopen('http://.../')
parser = parse(f)
stream.write('<geo>')
for prefix, event, value in parser:
    if (prefix, event) == ('earth', 'map_key'):
        stream.write('<%s>' % value)
        continent = value
    elif prefix.endswith('.name'):
        stream.write('<object name="%s"/>' % value)
    elif (prefix, event) == ('earth.%s' % continent, 'end_map'):
        stream.write('</%s>' % continent)
stream.write('</geo>')

Acknowledgements

Ijson was inspired by yajl-py wrapper by Hatem Nassrat. Though ijson borrows almost nothing from the actual yajl-py code it was used as an example of integration with yajl using ctypes.

Release files for ijson 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ijson 0.8.0
File Size Uploaded
ijson-0.8.0.tar.gz 5.8 kB Details

Release files / ijson-0.8.0.tar.gz

Download URL ijson-0.8.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ff36873499d9a14db3ef91e7e991562323cdbda94e26e27f9f9916a2f1a012b9
BLAKE2b-256 checksum
How to use checksums
8658136d4b339307d50ce486d1ad0ae026eed5ad108d922744731f42929f6c87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

3.5.0

95 release files

3.2.3

89 release files

3.2.2

78 release files

3.2.1

78 release files

3.1.3

61 release files

3.1.2

53 release files

3.1

20 release files

3.0.4

20 release files

3.0.3

20 release files

3.0.2

20 release files

3.0.1

21 release files

3.0

21 release files

2.6.0

13 release files

2.5

12 release files

2.4

12 release files

2.3

2 release files

2.2

2 release files

2.1

2 release files

2.0

2 release files

1.1

1 release file

1.0

1 release file

This release

0.8.0 This release

1 release file

0.7.0

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page