jsontypedef / json-typedef-codegen

A CLI tool that generates code from JSON Typedef schemas
https://jsontypedef.com/docs/tools/jtd-codegen
MIT License
160 stars 31 forks source link

Emit errors as json when `--log-format json` is set. #42

Open barlock opened 3 years ago

barlock commented 3 years ago

In wrapping the cli programmatically, it's easy to process std out with --log-format json. It would be convienent to also be able to parse errors in the same way.

For example, when parsing the invalid jtd:

{ "enum": [1, 2, 3] }

with --log-format json this is output to stderr

Error: Failed to parse input as JSON

Caused by:
      invalid type: integer `1`, expected a string at line 1 column 10

Something like this would be what I would expect:

{
    "error": "Failed to parse input as JSON",
    "cause": "invalid type: integer `1`, expected a string at line 1 column 10"
}