Merge doesn't work if first { is followed by newline
Using version 1b0951f for merging, if the first { is followed by a newline (\n), json dies with syntax error. Unfortunately, it's a common case with indented JSON input files. Here's an example:
$ echo -ne '{"key": {"foo": "bar"}}{\n"baz": "qux"}' | json --deep-merge
json: error: input is not JSON: Syntax error at line 1, column 24:
{"key": {"foo": "bar"}}{
.......................^
{"key": {"foo": "bar"}}{
"baz": "qux"}
Removing the newline leads to normal behavior:
$ echo -ne '{"key": {"foo": "bar"}}{"baz": "qux"}' | json --deep-merge
{
"key": {
"foo": "bar"
},
"baz": "qux"
}
Currently, I have to use the following workaround: for i in *.json; do json -o json-0 <$i; done | json --deep-merge
Perhaps related: I don't think this syntax error is valid:
echo '{ "foo": "bar" }{ "foo": "odp"}' | json --merge
json: error: input is not JSON: Syntax error at line 1, column 17:
{ "foo": "bar" }{ "foo": "odp"}
................^
{ "foo": "bar" }{ "foo": "odp"}
nick.heiner:~/opower/widget-neighbor-comparison [git: XWEB-1890-remove-new-relic] $ json --version
json 9.0.1
written by Trent Mick
https://github.com/trentm/json
nick.heiner:~/opower/widget-neighbor-comparison [git: XWEB-1890-remove-new-relic] $
@NickHeiner's comment should be it's own issue, I think. I'm seeing this too. Doing this, as in the docs:
cat test.json test2.json | json --merge gives the same error. Previously it didn't, of course.
@sinewave440hz I don't think so. It's the same behavior; whitespace after the opening { is treated as an error when merging JSONs. What's more sad, is that this issue has been open for more than 2 years, even though the project seems active (last commit was 15 days ago).
To be fair, I did open a new issue that dealt with this specifically and trent answered more or less right away. Discussion continues here: https://github.com/trentm/json/issues/115