/ex_ndjson

Implementation of Newline Delimited JSON (NDJSON) for Elixir

Primary LanguageElixirMIT LicenseMIT

ExNdjson

Build Status Hex.pm Version Hex.pm Download Total

ExNdjson is a Newline-delimited JSON library for Elixir that implements encoding and decoding to/from NDJSON as described in the NDJSON Spec.

Requirements

  • Elixir 1.6 or later

Installation

First, Add ExNdjson to you mix.exs dependencies:

def deps do
  [
    {:ex_ndjson, "~> 0.3.2"}
  ]
end

Then, update your dependencies:

mix deps.get

Usage

ExNdjson.marshal!([%{"some" => "thing"}, %{"bar" => false, "foo" => 17, "quux" => true}])
#=> "{\"some\":\"thing\"}\n{\"quux\":true,\"foo\":17,\"bar\":false}\n"

ExNdjson.marshal_into_file!([%{id: 1}, [1, 2, 3]], "/path/to/dump.ndjson")
#=> :ok

ExNdjson.unmarshal('{"some": "thing"}\n{"quux":true, "foo":17, "bar": false}\r\n')
#=> [%{"some" => "thing"}, %{"bar" => false, "foo" => 17, "quux" => true}]

ExNdjson.unmarshal(<<123, 125, 10>>)
#=> [%{}]

ExNdjson.unmarshal_from_file!("/path/to/ndjson/file")
#=> [%{"id" => "1"}, [1, 2, 3]]

Configuration

You can customize the library used for JSON encoding/decoding:

config :ex_ndjson, json_library: Poison # Defaults to Jason

Documentation

Full documentation can be found at https://hexdocs.pm/ex_ndjson.

License

The library is available as open source under the terms of the MIT License.