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 of two files no longer works #115

Open
sinewave440hz opened this issue Mar 17, 2017 · 6 comments
Open

Merge of two files no longer works #115

sinewave440hz opened this issue Mar 17, 2017 · 6 comments

Comments

@sinewave440hz
Copy link

Doing this, as in the docs:
cat test.json test2.json | json --merge gives the error:
json: error: input is not JSON: Syntax error at line 24, column 1: {
Previously it didn't, of course.

@trentm
Copy link
Owner

trentm commented Mar 18, 2017

Repro:

$ cat b.json a.json b.json
{"foo":2}{
    "foo": 1
}
{"foo":2}$
$ cat b.json a.json b.json | ./lib/json.js --merge
json: error: input is not JSON: Syntax error at line 1, column 10:
        {"foo":2}{
        .........^
{"foo":2}{
    "foo": 1
}
{"foo":2}

$ ./lib/json.js --version
json 9.0.6

@sinewave440hz However, I see this all the way back to json v4 when --merge was introduced:

$ json4 --version
(node) util.puts is deprecated. Use console.log instead.
json 4.0.1
[21:24:21 trentm@danger0:~/tm/json (master)]
$ cat b.json a.json b.json | json4 --merge
json: error: input is not JSON: Syntax error at line 1, column 10:
        {"foo":2}{
        .........^
{"foo":2}{
    "foo": 1
}
{"foo":2}

Can you show me a case (showing the specific test.json and test2.json content) where that works in an earlier version of json and fails on newer versions? Thanks.

@sinewave440hz
Copy link
Author

Apparently not, I tried on earlier versions last night and got the same result. I haven't dug much further into it, but I had a script working earlier that combined two package.jsons successfully. This was on a much older node.js though - 4.4.7. I will try and put aside some time to take a look at this, but in the meantime, how can we do the equivalent of the merge example in your docs, but with files? Any suggestions?

@trentm
Copy link
Owner

trentm commented Mar 20, 2017

My bet is that the difference is that your files don't end with a newline. I think jsons current attempts to handle adjacent JS objects with --merge and -g have limitations when there are two incomplete objects on a given line.

@eddyparkinson
Copy link

Merge error work around

  • Fails:

$ json -f dump.json -f dump_new.json --merge >dump_merge.json
json: error: input is not JSON: Syntax error at line 20427, column 2:
        }{
        .^

  • works:

$ json -f dump.json  >dump_1.json
$ json  -f dump_new.json >dump_2.json
$ json --merge -f dump_1.json -f dump_2.json  >dump_merge.json

@kondaurovDev
Copy link

@eddyparkinson , didn't understand your example

@trentm has said right thing, your files with json must have empty line in the end

@eddyparkinson
Copy link

json is not good with newlines. It is very picky when merging. But if you first do

json -f filename.json >tmpfile.json

then it fixes the newlines. tmpfile.json will have the needed newlines and can be used with json --merge

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

4 participants