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

JSON file #36

Open
mwallach opened this issue Sep 27, 2018 · 1 comment
Open

JSON file #36

mwallach opened this issue Sep 27, 2018 · 1 comment

Comments

@mwallach
Copy link

I have json file that looks like below. json2csv works if I make this each entry a single line. Is this format it fails. I there a way for json2csv handle file formatted in this way?
{
“count”:10,
“entries”:
[
{
“id”:20232913,
“application”:“AuditExampleLogin1”,
“user”:“TestUser”,
“time”:“2018-08-15T23:59:40.186-07:00”,
“values”:
null
},
{
“id”:20232914,
“application”:“AuditExampleLogin1”,
“user”:“AUser”,
“time”:“2018-08-15T23:59:55.186-07:00”,
“values”:
null
},

@grocky
Copy link

grocky commented Apr 24, 2019

You can convert the entries array to produce a JSONL file (or stream) and then pass it to json2csv.

For example, given the following json

sample.json

{
  "count":10,
  "entries":
  [
    {
      "id":20232913,
      "application":"AuditExampleLogin1",
      "user":"TestUser",
      "time":"2018-08-15T23:59:40.186-07:00",
      "values":
      null
    },
    {
      "id":20232914,
      "application":"AuditExampleLogin1",
      "user":"AUser",
      "time":"2018-08-15T23:59:55.186-07:00",
      "values":
      null
    }
  ]
}

You could create the JSONL file with jq:

< sample.json jq -c '.entries[] | { id, application, user, time }' > sample.jsonl

Then you can use json2csv to convert it to a CSV:

< sample.jsonl json2csv -p -k id,application,user,time > sample.csv

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

2 participants