2

I've got a nested json object. For the sake of simplicity:

data = {'key1': 1, 'key2': 2, 'key3': {'nestedKey1': 3, 'nestedKey2': 4}}

A real object is bigger but the point is that it's a nested one. Values may be strings, numbers or other objects. Now I need to get an excel table that (for this specific json would look like this):

|----------------------------------------
| key1 | key2 |           key3          |
|      |      |--------------------------
|      |      | nestedKey1 | nestedKey2 |
|----------------------------------------
|  1   |  2   |     3      |      4     |
|----------------------------------------

Other formats are also acceptable. But this one is most preferable. How do I do that?

GoBear
  • 518
  • 1
  • 5
  • 19

2 Answers2

0

You can convert online(don't know the size limit they allow)

Although it is not exactly in the same format you expect but it is very much similar, you can do little bit of modification from the output you get here. Here is a sample screenshot of the output I got when I inserted your json. enter image description here

Stackoverflow

If you want to write a Service on your own then you can refer to this question on SOF. It is something similar to what you want and it is written in JavaScript.

JQuery

Here is a JQuery script on this page for converting JSON to excel.

Working Stackblitz

Cpt Kitkat
  • 1,392
  • 4
  • 31
  • 50
  • No, I can't do that, I need to write a service that does just that. I tried using 'xlsx' but I can't figure out how to make it write the table in the right format – GoBear Jun 18 '19 at 05:49
  • You need to write it in which language. I mean which tools and framework are you working on ? – Cpt Kitkat Jun 18 '19 at 06:07
  • Ah, sorry I forgot to mention it. The framework is angular, the language is typescript. – GoBear Jun 18 '19 at 07:53
  • @GoBear Ihave updated my answer have a look at the stackblitz example. I think that should be sufficient for your requirement – Cpt Kitkat Jun 18 '19 at 08:44
0

I have written a python package that you can use to convert complex json into excel. https://github.com/akritianand/JsonToExcel

Akriti Anand
  • 166
  • 3
  • 17