Hacker News new | ask | show | jobs
by thatsnice 2452 days ago
I made a Google spreadsheet add-on [1] that contains 3 built-in options for converting nested JSON to tabular format.

Method 1: drills into nested json objects and arrays and returns the key names as headers, key values as rows. In cases with multiple nested values, they get returned into multiple columns, differentiated by a number, e.g. orders > products > 1, orders > products > 2.

Method 2: same as above but returns all nested data into a single column, e.g. a single column named orders > products. This can break the association between JSON elements, but is more convenient for certain types of analysis.

Method 3: concatenates all the elements of each nested object into a single cell, separated with pipes.

In some cases (e.g. when the primary object of interest is nested inside another object) there are still problems recognizing what keys should represent rows vs columns, but in my tests the above 3 algorithms cover most of the use cases for spreadsheets.

[1] https://mixedanalytics.com/knowledge-base/report-styles/

1 comments

You could put the nested data into a separate sheet with a unique identifier for the row. Then include a foreign key back to the original sheet's primary id.
Interesting idea, thanks. There's often multiple levels of nested data, would you want to see each level in a new sheet?
Absolutely! It's relational data that could map to a defined relational schema, so why not?
As I described on another reply, SpreadOn not only supports a tree structured format, but also has tags for referring to entire sheets by name, for declaring grids of identically-typed data, for referring to named regions and extracting subsets of them, and compactly defining tables of repeating structures, which you can mix on a case-by as they make sense. (You can't embed a grid in another grid since it requires more than one cell, but you can make a grid of sheet references, since the sheet name only takes one cell and can be put into a grid.)

There is no "one best way" to represent JSON data in spreadsheets, because JSON data comes in all sizes and shapes, so SpreadON tries to support many different useful formats that you can link together, with a simple straightforward syntax that can be easily extended without breaking existing documents.