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

flatten nested object properties for json array data preview display #168

Closed
AiaRup opened this issue Dec 2, 2019 · 10 comments
Closed

flatten nested object properties for json array data preview display #168

AiaRup opened this issue Dec 2, 2019 · 10 comments
Labels
data Data related task enhancement New feature or request UX User Experience enhancement

Comments

@AiaRup
Copy link

AiaRup commented Dec 2, 2019

Hello,
I tried to view a JSON in the data-preview but it appears as [object object].

The raw data looks like this (mongo document):
Screenshot 2019-12-02 at 13 04 30

When I preview only one document it looks like this as a preview:
Screenshot 2019-12-02 at 13 04 51

When I want to look at several documents in a JSON file I see the [object object]:
Screenshot 2019-12-02 at 13 06 09

I don't know if it is a bug or I need to configure something?
Thank a lot!

@RandomFractals
Copy link
Owner

RandomFractals commented Dec 2, 2019

@AiaRup your first example is just a json config that is converted to flat properties list per this note in docs: https://github.com/RandomFractals/vscode-data-preview#data-preview--files-loading-details

Your 2nd example is most likely a json array. However, that json document has nested object properties for the _id and group properties & data preview doesn't try to expend them.

Perhaps, it could be improved for the latter use case.

Current json array display works best with json docs that contain flat objects, such as in this example: https://github.com/RandomFractals/vscode-data-preview/blob/master/data/json/cars.json

@RandomFractals
Copy link
Owner

RandomFractals commented Dec 2, 2019

the only sensible solution for this use case I can propose and try to implement is flattening those objects, so that your json array grid will have the following headers:

_id.$oid, resource, actions, group.$oid

this is due to the fact that json can be hierarchical, but we are displaying that data in a grid of rows and columns, which is a flat 2 dimensional format :(

@RandomFractals RandomFractals changed the title View json file appears as [object object] flatten nested object properties for json array data preview display Dec 2, 2019
@RandomFractals RandomFractals added data Data related task enhancement New feature or request UX User Experience enhancement labels Dec 2, 2019
@AiaRup
Copy link
Author

AiaRup commented Dec 2, 2019

the only sensible solution for this use case I can propose and try to implement is flattening those objects, so that your json array grid will have the following headers:

_id.$oid, resource, actions, group.$oid

this is due to the fact that json can be hierarchical, but we are displaying that data in a grid of rows and columns, which is a flat 2 dimensional format :(

It seems perfect, thanks a lot for all your hard work!

@RandomFractals
Copy link
Owner

RandomFractals commented Dec 2, 2019

btw, data preview also supports .jsonl format, if you just want to create a single json doc using cat Unix command and then preview that json data dump :)

see issue #159 for more info

@RandomFractals
Copy link
Owner

RandomFractals commented Dec 2, 2019

I am only bringing up jsonl since that and csv/tsv data formats will be the first to get data streaming implemented in the next v. update this month most likely.

With data streaming you'll be able to view hundreds of thousands of data rows. More info here: #167

So, if you script your mongo db data dump that way, you'll be good to go and see more data loaded faster in the next data preview ext. update.

@RandomFractals
Copy link
Owner

@AiaRup btw, I also have mongoDB data connector penciled in for the data preview wish/todo list, but I don't think I'll get to it this year: #26

Thumb it up & if I see more devs interested in that feature, I might move it up the implementation list :)

@AiaRup AiaRup mentioned this issue Dec 2, 2019
Closed
@AiaRup
Copy link
Author

AiaRup commented Dec 2, 2019

I am only bringing up jsonl since that and csv/tsv data formats will be the first to get data streaming implemented in the next v. update this month most likely.

With data streaming you'll be able to view hundreds of thousands of data rows. More info here: #167

So, if you script your mongo db data dump that way, you'll be good to go and see more data loaded faster in the next data preview ext. update.

I will check it out, thank you so much!

@RandomFractals
Copy link
Owner

might try using json-2-csv for this prior to passing nested json objects to the grid view display which is tabular ...

https://github.com/mrodrig/json-2-csv

@RandomFractals
Copy link
Owner

RandomFractals commented Sep 28, 2020

actually, might try this json-spread lib instead: https://github.com/gone369/json-spread

or: https://github.com/hughsk/flat

@RandomFractals
Copy link
Owner

probably the best we can do to flatten json arrays with nested objects for now:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data Data related task enhancement New feature or request UX User Experience enhancement
Projects
None yet
Development

No branches or pull requests

2 participants