Flatten arrays
See original GitHub issueIt would be cool, if the library would allow serializing arrays as scalar values like:
input:
[{
name: "Jack",
age: 39,
friends: [{ name: "Oliver", age: 40 }, { name: "Harry", age: 50 }],
}, {
name: "Thomas",
age: 40,
friends: [{ name: "Harry", age: 35 }]
}]
output:
name,age,friends.0.name,friends.0.age,friends.1.name,friends.1.age
Jack,39,Oliver,40,Harry,50
Thomas,40,Harry,35
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Array.prototype.flat() - JavaScript - MDN Web Docs
The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
Read more >JavaScript: Flatten an array using different methods - Flexiple
Flattening an array is a process of reducing the dimensionality of an array. In other words, it a process of reducing the number...
Read more >Merge/flatten an array of arrays - javascript - Stack Overflow
flat () method which you could use to flatten the arrays. It is compatible with most environments, although it is only available in...
Read more >7 Ways to Flatten Arrays in JavaScript | by Zachary Lee
Array flattening is to convert multi-layer nested arrays to only one layer. To explain it in code, it would be [1, [2, [3,...
Read more >How to Flatten a Nested Javascript Array | by Cynthia Okoliezeh
To flatten an array means to reduce the dimensionality of an array. In simpler terms, it means reducing a multidimensional array to a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we could do a backward compatible version, maybe even keeping
flatten
as-is and addingflattenArrays
option. My rational is that this seems like a fringe case, since we are just now seeing a request for it and there probably won’t be additional options to flatten of the same nature, since there is no other complex data structures that you’d see in json. If we do see a reason for making it one option, we could do that in a future major version, e.g. v5.I like
flatten = true|'objects'|'arrays'|false
more, but I understand that I would introduce backward incompatible change, which is probably OK for major version change. Do you mean, that true would flatten both objects and arrays, right? I just can’t see use case forflatten = 'arrays'
. Maybe ```flatten = true|‘evenArrays’|false would be better since it could be backward compatible when true means flatten just objects.