Closed raghuugare closed 7 years ago
@raghuugare The reason why handling nested objects is not implemented is there are so many different cases in nested json objects. It can be nested objects as the example you gave or it can be nested objects with nested arrays. I faced the same problem as well; however, it is doable depends on individual case.
First, you need to consider the format of the CSV.
Using your example and I want my CSV looks like:
And then convert your example to an array of json objects (get rid of all the nested objects or arrays into a single array of objects):
[{first_name: 'Raghu', last_name: 'Ugare', 'city': 'Cambridge', 'state': 'MA' } ]
I will suggest you to take a look underscore.js
library to help you manipulating objects.
The directive like this should not be responsible for JSON manipulation, there is plenty of libraries you can use to resolve your cyclic references, nested objects etc. JSON3, JSON-js, JSONPath. Sometime in a future galaxies away someone could send the PR with unparse part of the https://github.com/mholt/PapaParse
hi @raghuugare , I have a small project, it used to export excel from json. I support nested json.You can refer
Thanks a lot @shaohaolin , @adyba and @dtagdev1 !
@raghuugare The reason why handling nested objects is not implemented is there are so many different cases in nested json objects. It can be nested objects as the example you gave or it can be nested objects with nested arrays. I faced the same problem as well; however, it is doable depends on individual case.
First, you need to consider the format of the CSV. Using your example and I want my CSV looks like:
And then convert your example to an array of json objects (get rid of all the nested objects or arrays into a single array of objects):
[{first_name: 'Raghu', last_name: 'Ugare', 'city': 'Cambridge', 'state': 'MA' } ]
I will suggest you to take a look
underscore.js
library to help you manipulating objects.
Imo the easiest solution. Thanks @shaohaolin
Hi,
I am trying to fetch some records from MongoDB, where there are some properties whose value itself is a nested JSON object. Is there an easy method to 'un-pack' the nested properties into top-level CSV columns.
E.g., suppose I have an array of
n
objects of the following format:{ first_name: 'Raghu', last_name: 'Ugare', location: { 'city': 'Cambridge', 'state': 'MA' } }
I know we can easily map
first_name
&last_name
as columns. But is there a simple way to maplocation.city
&location.state
as well? Or should we do it manually?Thanks for this anyways!