ExQuality.Json (ExQuality v0.13.0)

View Source

Reads a JSON document out of a command's output.

A tool asked for --format json writes JSON, but it is rarely the only thing on the stream: mix compiles the project first, and anything it or the tool prints lands ahead of the report. So the document is looked for rather than assumed.

Three candidates are tried, in order: the whole output, each line that opens an object on its own (a compact document, as mix deps.audit writes), and the rest of the output from each such line (a pretty-printed one, as mix credo writes). Only lines opening in column one are considered, so a large document's nested objects are not each tried as a document of their own.

Returns :error rather than raising, because a tool that printed no JSON is something the caller has to report, not something it can fix.

Summary

Functions

Decodes the JSON document in output, or returns :error.

Functions

decode(output)

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

Decodes the JSON document in output, or returns :error.

iex> ExQuality.Json.decode(~s|Compiling 3 files\n{"issues": []}|)
{:ok, %{"issues" => []}}

iex> ExQuality.Json.decode("** (Mix) Could not invoke task")
:error