ak.to_json — Awkward Array documentation

# ak.to_json

Defined in awkward.operations.convert on line 1142.

ak.to_json(array, destination=None, pretty=False, maxdecimals=None, nan_string=None, infinity_string=None, minus_infinity_string=None, complex_record_fields=None, buffersize=65536)
  Parameters:

    - array – Data to convert to JSON.

    - destination (None or str) – If None, this function returns a JSON str; if a str, it uses that as a file name and writes (overwrites) that file (returning None).

    - pretty (bool) – If True, indent the output for human readability; if False, output compact JSON without spaces.

    - maxdecimals (None or int) – If an int, limit the number of floating-point decimals to this number; if None, write all digits.

    - nan_string (None or str) – If not None, floating-point NaN values will be replaced with this string instead of a JSON number.

    - infinity_string (None or str) – If not None, floating-point positive infinity values will be replaced with this string instead of a JSON number.

    - minus_infinity_string (None or str) – If not None, floating-point negative infinity values will be replaced with this string instead of a JSON number.

    - complex_record_fields (None or (str, str)) – If not None, defines a pair of field names to interpret records as complex numbers.

    - buffersize (int) – Size (in bytes) of the buffer used by the JSON parser.

Converts `array` (many types supported, including all Awkward Arrays and Records) into a JSON string or file.

Awkward Array types have the following JSON translations.

> - `ak.types.PrimitiveType`: converted into JSON booleans and numbers.

> - `ak.types.OptionType`: missing values are converted into None.

> - `ak.types.ListType`: converted into JSON lists.

> - `ak.types.RegularType`: also converted into JSON lists. JSON (and Python) forms lose information about the regularity of list lengths.

> - `ak.types.ListType` with parameter `"__array__"` equal to `"__bytestring__"` or `"__string__"`: converted into JSON strings.

> - `ak.types.RecordArray` without field names: converted into JSON objects with numbers as strings for keys.

> - `ak.types.RecordArray` with field names: converted into JSON objects.

> - `ak.types.UnionArray`: JSON data are naturally heterogeneous.

See also `ak.from_json` and `ak.Array.tojson`.