Skip to content

adjunct.jsonutils

load_json_documents(payloads)

Load multiple JSON documents from a string.

Each JSON document is expected to be separated by whitespace or newlines.

This is useful for processing streams of JSON objects, such as logs or data exports, where each line or block represents a separate entity.

Parameters:

Name Type Description Default
payloads str

A text stream containing JSON documents.

required

Yields:

Type Description
dict | list

Parsed JSON objects/lists.

Examples:

>>> json_stream = '''
... {"name": "Alice"}
... {"name": "Bob"}
... [1, 2, 3]
... '''
>>> for doc in load_json_documents(json_stream):
...     print(doc)
{'name': 'Alice'}
{'name': 'Bob'}
[1, 2, 3]