DeclanMcD
DeclanMcD

Reputation: 1586

How to analyse JSON data size

I have a JSON data file that is quite large and I want to analyse the data structure to see where I can make improvements. What I would like is some kind of analyser like the ones you that will analyse your had disk structure and report the size in bytes of the tree node and below.

My JSON format has many levels and it would take quite a while to trawl through each node manually.

So what is the best way to deep analyse the JSON structure to report the data size of each node? Ideally it will analyse any JSON data format and report on it.

The REST service is in C#, but I can't see the analysis being done server side because access to the service code may not always be available, which is why I imagine a plug-in or independent tool being the order of the day?

For example I use Fiddler to analyse the JSON data, so ideally I would like to copy that JSON directly out of Fiddler and paste it into something that will give me the results. jsonviewer.stack.hu do something close, but don't have the data size

Upvotes: 5

Views: 1540

Answers (2)

Alex D
Alex D

Reputation: 170

Found this question, but some online tool would be enough for me for quick quick review of issue with enormous JSON response size. So there's great one: https://www.debugbear.com/json-size-analyzer

Upvotes: 6

wvdz
wvdz

Reputation: 16651

Write a function getSize that recursively determines the size of a node and prints it.

Pseudocode:

   function getSize(node, level)
     sum = 0
     if node has no children
       return length(node.value)
     for child in node.children
       sum += getSize(child, level + 1)
     print indentation based on level, node, sum
     return sum

Upvotes: 1

Related Questions