Skip to content

Chunked JSON

influxdb.chunked_json

Module to generate chunked JSON replies.

Functions

loads(s)

Generate a sequence of JSON values from a string.

Parameters:

Name Type Description Default
s str

JSON string to parse

required

Yields:

Name Type Description
dict

JSON objects parsed from the string

Raises:

Type Description
ValueError

if no JSON object is found

Source code in influxdb/chunked_json.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def loads(s):
    """Generate a sequence of JSON values from a string.

    Args:
        s (str): JSON string to parse

    Yields:
        dict: JSON objects parsed from the string

    Raises:
        ValueError: if no JSON object is found

    """
    _decoder = json.JSONDecoder()

    while s:
        s = s.strip()
        obj, pos = _decoder.raw_decode(s)
        if not pos:
            raise ValueError("no JSON object found at %i" % pos)
        yield obj
        s = s[pos:]