ex_ndjson v0.3.2 ExNdjson

Implements encoding and decoding of NDJSON as defined in NDJSON Spec.

Link to this section Summary

Functions

Returns the NDJSON encoding of v, raises an exception on error

Returns the NDJSON encoding of v and saves it to the specified path, raises an exception on error

Parses the NDJSON-encoded data and returns a list of decoded JSON values

Parses the NDJSON-encoded lines in the given path and returns a list of decoded JSON values. Raises an exception if failed to open the file.

Examples

Link to this section Types

Link to this type

t()
t() :: nil | true | false | list() | float() | integer() | String.t() | map()

Link to this section Functions

Link to this function

marshal!(v)
marshal!([t()]) :: String.t() | no_return()

Returns the NDJSON encoding of v, raises an exception on error.

Examples

iex> ExNdjson.marshal!([%{id: 1}, [1, 2, 3]])
"{"id": "1"}\n[1, 2, 3]\n"
Link to this function

marshal_into_file!(v, path)
marshal_into_file!([t()], Path.t()) :: :ok | no_return()

Returns the NDJSON encoding of v and saves it to the specified path, raises an exception on error.

Examples

iex> ExNdjson.marshal_into_file!([%{id: 1}, [1, 2, 3]], "dump.ndjson")
:ok
Link to this function

unmarshal(v)
unmarshal(iodata()) :: [t()]

Parses the NDJSON-encoded data and returns a list of decoded JSON values.

Examples

iex> ExNdjson.unmarshal('{"id": "1"}\n[1, 2, 3]\r\n')
[%{"id" => "1"}, [1, 2, 3]]
Link to this function

unmarshal_from_file!(path)
unmarshal_from_file!(Path.t()) :: [t()] | no_return()

Parses the NDJSON-encoded lines in the given path and returns a list of decoded JSON values. Raises an exception if failed to open the file.

Examples

iex> ExNdjson.unmarshal_from_file!("./fixtures/file.txt")
[%{"id" => "1"}, [1, 2, 3]]