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.

Wrong placement in multi-array set

See original GitHub issue

Here’s my code

var test = [
    {
      "name" : "John",
      "clases" : [
        {
          "year" : 2016,
          "grade" : "1st",
          "payment":[
            {
              "type":"monthly",
              "status":"done"
            },
            {
              "type":"yearly",
              "status":"done"
            }
          ]
        },
        {
          "year" : 2017,
          "grade" : "2nd",
          "payment":[
            {
              "type":"monthly",
              "status":"in progress"
            },
            {
              "type":"yearly",
              "status":"done"
            }
          ]
        }
      ],
      
    },
    {
      "name" : "Andrew",
      "clases" : [
        {
          "year" : 2017,
          "grade" : "1nd",
          "payment":[
            {
              "type":"monthly",
              "status":"in progress"
            },
            {
              "type":"yearly",
              "status":"in progress"
            }
          ]
        }
      ]
    },
    
  ]

jsonexport(test,function(err, csv){
    if(err) return console.log(err);
    console.log(csv);
});

and here is the output

name,clases.year,clases.grade,clases.payment.type,clases.payment.status
John,2016,1st,monthly,done
,2017,2nd,yearly,done
,,,monthly,in progress
,,,yearly,done
Andrew,2017,1nd,monthly,in progress
,,,yearly,in progress

capture

as you can see, the values are not supposed to be there. It should drop on the next line. And is there any option to force rewrite values so it would be look like this?

capture

Thank you…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AckerApplecommented, Sep 2, 2017

My thought is that it will get awfully ugly and convoluted for arrays inside arrays, or array of objects with arrays.

I wouldn’t approach this one as a catering company. Don’t do, a change like this needs an accompanying document type. CSV doesn’t have metadata by nature. You best stick to as little format variations as possible.

We can do anything, don’t think we should for consistency sake

1reaction
AckerApplecommented, Sep 2, 2017

I abolsutely think this issue should be closed.

@saipallavi, I have starred your example over for quite sometime. I disagree with you, I see expected result. A child-arrary’s first row belongs with-in the parent row. If jsonexport did what you are asking for, it’d be a hard breaking change. Your “I need the output like this” example, would actually mean you have a 2nd parent who’s CODE, GROUP_NAME, and GROUP_DESC are all null but has a 3 child length array (not to mention row 1 has no children).

Lets close this. Wouldn’t even offer an option to pivot the behavior to keep tight format standards

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - 2D Array - wrong "Wall " placement? - Stack Overflow
In the inner for-loop of your setRoomFloor method, you're inverting the position on the x-axis and the position on the y-axis.
Read more >
Boost.MultiArray Reference Manual - 1.68.0
It specifies operations for accessing elements, traversing containers, and creating views of array data. MultiArray defines a flexible memory model that ...
Read more >
FB_CMA_SourcePaired - Beckhoff Information System - English
Writes data from external two-dimensional data buffers to a pair of MultiArrays. This method must be called whenever new input samples are available,...
Read more >
PowerShell Multidimensional Array | Initialization of ... - eduCBA
If we defined array as strictly type and we are trying to assign different data types of then it will throw an error....
Read more >
How to initialize (or Declare) a multidimensional array
Not declaring how many items in each row will give you this cryptic error: "multidimensional array must have bounds for all dimensions except ......
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