pg_utils.numerics.io.CompactArrayJSONEncoder

class pg_utils.numerics.io.CompactArrayJSONEncoder(*args, **kwargs)[source]

Bases: JSONEncoder

A Json encoder that puts long arrays on one line

This encoder is adopted from the encoder written by Jannismain for compressing small containers on single lines.

__init__(*args, **kwargs)[source]

Methods

__init__(*args, **kwargs)

default(o)

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

encode(o)

Encode JSON

iterencode(o[, _one_shot])

Encode the given object and yield each string representation as available.

Attributes

CONTAINER_TYPES

SINGLELINE_THRESHOLD

indent_str

item_separator

key_separator

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
encode(o) str[source]

Encode JSON

iterencode(o, _one_shot=False)[source]

Encode the given object and yield each string representation as available.

For example:

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)