question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

const { Parser,transforms: { unwind } } = require('json2csv');
 
const myCars = [
 {
    "carModel": "Porsche",
    "price": 30000,
    "items": [
      {
        "name": "airbag",
        "items": [
          {
            "position": "left",
            "color": "white"
          }, {
            "position": "right",
            "color": "gray"
          }
        ]
      }, {
        "name": "dashboard",
        "items": [
          {
            "position": "left",
            "color": "gray"
          }, {
            "position": "right",
            "color": "black"
          }
        ]
      }
    ]
  }
];
 
const fields = ['carModel', 'price', 'items.name', 'items.color', 'items.items.position', 'items.items.color'];
const transforms = [unwind(['items', 'items.items'])];
const json2csvParser = new Parser({ fields, transforms });
const csv = json2csvParser.parse(myCars);
 console.log(csv);

output:

"carModel","price","items.name","items.color","items.items.position","items.items.color"
"Porsche",30000,"airbag",,"left","white"
"Porsche",30000,"airbag",,"right","gray"
"Porsche",30000,"dashboard",,"left","gray"
"Porsche",30000,"dashboard",,"right","black"

But if I remove one item from myCars[0].items[]

const { Parser,transforms: { unwind } } = require('json2csv');
 
const myCars = [
 {
    "carModel": "Porsche",
    "price": 30000,
    "items": [
      {
        "name": "airbag",
        "items": [
          {
            "position": "left",
            "color": "white"
          }, {
            "position": "right",
            "color": "gray"
          }
        ]
      }
    ]
  }
];
 
const fields = ['carModel', 'price', 'items.name', 'items.color', 'items.items.position', 'items.items.color'];
const transforms = [unwind(['items', 'items.items'])];
const json2csvParser = new Parser({ fields, transforms });
const csv = json2csvParser.parse(myCars);
console.log(csv);

output:

"carModel","price","items.name","items.color","items.items.position","items.items.color"
"Porsche",30000,"airbag",,,

Not printing “items.items.position”,“items.items.color”

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
knownasilyacommented, Apr 28, 2020

Already released 😄

0reactions
juanjoDiazcommented, Apr 28, 2020

Not sure if it’s worth doing a release just for a small documentation fix.

But I don’t think that we will have anything else to release anytime soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Exploiting Parsing Bugs - Black Hat
Exploiting Parsing Bugs. Greg Hoglund. Cenzic, Inc. Page 2. What is parsing? Page 3. State Machines. SYSTEM A. SYSTEM B. GET /..\/..\/..\/..\etc\passwd ...
Read more >
Parsing, Parsing, Parsing | Groove Blog - Groove HQ
Parsing problems reveal themselves in the UI two ways, either by sending blank or empty replies in the place of a customer's response,...
Read more >
Bug in parsing for some multi-page Documents, #1 - GitHub
When parsing some multi-page outputs, there's a bug in the trp.py file. Due to which the keys in the blockmap at line 142...
Read more >
URL Parsing-Library Bugs Allow DoS, RCE, Spoofing & More
URL parsing is the process of breaking down a web address into its underlying components, in order to correctly route traffic across different ......
Read more >
Question:Bugs in parsing? - MaplePrimes
Hello there! Maple 2016.1 sometimes gets crasy about parsing input strings. I managed to capture this behaviour in the attached file.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found