# `ExQuality.Json`
[🔗](https://github.com/riddler/ex_quality/blob/v0.15.0/lib/ex_quality/json.ex#L1)

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.

# `decode`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
