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

Can't concat multiple files #4

Open
rafalagunas opened this issue Mar 18, 2019 · 5 comments
Open

Can't concat multiple files #4

rafalagunas opened this issue Mar 18, 2019 · 5 comments

Comments

@rafalagunas
Copy link

rafalagunas commented Mar 18, 2019

Here is my code, I'm trying to concat multiple files in xfiles folder.

jsonConcat( { src: "./xfiles", dest: "./result.json" }, function(json) { console.log(json); } );

this is what returns on console:
null

result.json only contains one of the files.

Thank you.

@lukejamestaylor
Copy link

I'm also experiencing the same issue. If the change function(json) to function(err, json), you can then log out the JSON file.

Still it only returns 1 file for me.

@GochoMugo
Copy link
Owner

Is it possible to provide the files to be able to reproduce this bug.

Also note that the library is forgiving in that if a file could not be parsed, it will be skipped over.

@guyaumetremblay
Copy link

guyaumetremblay commented Aug 10, 2021

EDIT: After digging, I found this so I replace my comment with this better one:

@GochoMugo Get the same issue here. The bug seems to be cause by one of the 3 replaces in the concat method, line 144 of json-concat.js.

As each of my json file contain an object, the result should be an array of object. But, by replacing }{ by a single coma, the result is only one big object.

For example, taking these two files:

File A

{
    "name": "John"
} 

File B

{
    "name": "Doe"
} 

Final string after before the replace:

{
    "name": "John"
}
{
    "name": "Doe"
} 

And after the replace:

{
    "name": "John"
,
    "name": "Doe"
} 

Expected result:

[
    {
        "name": "Doe"
    },
    {
        "name": "Doe"
    } 
]

Without the replace, that should work as the JSON.parse will throw an exception for invalid format and your logic will use the contentArray variable.

@guyaumetremblay
Copy link

@GochoMugo Just saw that the logic in the catch loop on the item in contentArray and merge them into a single object... so it'll not create an array of object.

@steveDL
Copy link

steveDL commented Sep 30, 2022

Has this bug been fixed?

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

5 participants