NPM.JSON (NPM v0.7.4)

Copy Markdown View Source

JSON helpers for npm manifest and lock files.

npm_ex writes generated JSON files such as package.json, npm.lock, and shrinkwrap files. Those files should be stable across repeated writes, so maps are recursively converted to Jason.OrderedObject values sorted by key before encoding. Jason handles the actual JSON encoding, escaping, duplicate-key checks, and pretty formatting.

Summary

Functions

Decode JSON into maps with string keys.

Decode JSON into maps with string keys, raising on invalid input.

Encode a term as pretty-printed JSON with recursively sorted object keys.

Read and decode a JSON file.

Functions

decode(data)

@spec decode(iodata()) :: {:ok, term()} | {:error, Jason.DecodeError.t()}

Decode JSON into maps with string keys.

decode!(data)

@spec decode!(iodata()) :: term()

Decode JSON into maps with string keys, raising on invalid input.

encode_pretty(data)

@spec encode_pretty(term()) :: String.t()

Encode a term as pretty-printed JSON with recursively sorted object keys.

read_file(path)

@spec read_file(String.t()) :: {:ok, term()} | {:error, term()}

Read and decode a JSON file.