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 section Functions
marshal!(v)
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"
marshal_into_file!(v, path)
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
unmarshal(v)
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]]
unmarshal_from_file!(path)
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]]