zemirco / json2csv

Convert json to csv with column titles
http://zemirco.github.io/json2csv
MIT License
2.72k stars 362 forks source link

Escaping Issue & Console Window closes prematurely #547

Open TacticalMask opened 2 years ago

TacticalMask commented 2 years ago

FIRST ISSUE

  1. Version: 5.0.6
  2. v16.13.1

My JSON may contain segments like

' "text": "@accountName1 \n@accountName2", '

from

        "id": <number>,
        "created_at": <number>,
        "text": "@accountName1 \n@accountName2",
        "owner": { ...

which is from a comment section. I assume the user is including a new line entry which registers as the '\n'. My problem is when I convert to csv, that '\n' causes an error in the output, such that:

Line X ends with ';"@accountName1 ' Line X+1 starts with '@accountName2";'

Whereas in other areas it outputs as: Line Y contains ';"@accountName1 @accountName2";' which is what I desire.

  1. My command is: json2csv -d ; --flatten-objects -i <input> -o <output>

I think in my research, this problem is referred to as an escaping issue? I've tried the -q and -Q commands to no avail. How do I resolve this issue?

SECOND ISSUE

I'm running the json2csv command as part of a batch file that I execute through Windows CMD. However, the json2csv command closes my console window.

  1. json2csv -d ; --flatten-objects -i <input> -o <output> ... this would process and output the relevant csv file, but the next command from the batch file never executes.

  2. @for %%d in (%cd%\#Results\*.json) do echo %%d && json2csv -d ; --flatten-objects -i %%d -o %%d.csv ... this would process, outputting the relevant csv files until the final step in the loop. The final json file in the target source gets converted to a csv file, but then the next command in my batch file is not run and the console window closes.

I'm not sure what is the cause of this.

juanjoDiaz commented 2 years ago

Hi @TacticalMask ,

I definitely seem like an escaping issue. What do you mean when you say that some lines have the wrong new line but others done? What differences are there between line X and Y to produce the difference?

Can you provide some input data for me to replicate the issue?

juanjoDiaz commented 2 years ago

Regarding the console issue, it sounds like an issue on your script. Have you script that json2csv is returning the correct exit code? Are you doing any other check or action that might case the failure?