Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge doesn't work if first { is followed by newline #44

Open
dnet opened this issue Feb 2, 2013 · 5 comments
Open

Merge doesn't work if first { is followed by newline #44

dnet opened this issue Feb 2, 2013 · 5 comments

Comments

@dnet
Copy link

dnet commented Feb 2, 2013

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"
}
@dnet
Copy link
Author

dnet commented Feb 2, 2013

Currently, I have to use the following workaround: for i in *.json; do json -o json-0 <$i; done | json --deep-merge

@NickHeiner
Copy link

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] $ 

@sinewave440hz
Copy link

@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.

@dnet
Copy link
Author

dnet commented Mar 18, 2017

@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).

@sinewave440hz
Copy link

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: #115

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants