0

I am very new to JSON and am not sure if the term "multi-level" json is correct. If not, please help correct it.

I have been tasked with printing the request and response structure of a given rest service. I have the api.json which refers to a host of json objects, which in turn refer to other json objects and so on...

Please note that I am interested in printing the structure and not the contents of the request and response.

I know that I can go ahead and do a recursive read of the files and get this done. But that does not seem right.

Can someone please provide some pointers for the same?

Karthick S
  • 3,204
  • 6
  • 36
  • 52
  • Are you looking for this ? - http://stackoverflow.com/questions/7341537/tool-to-generate-json-schema-from-json-data – Ninad Pingale Jun 20 '14 at 07:41
  • This list links various options for this http://stackoverflow.com/questions/7341537/tool-to-generate-json-schema-from-json-data – Ninad Pingale Jun 20 '14 at 07:42

1 Answers1

0

There is a general misconception about JSON. JSON is a format to represent a complex data structure as a string. That's it. JSON itself doesn't know anything about structure - it's really just a string. What you can do is parse the JSON string to get JavaScript objects (i.e. numbers, strings, arrays and things of type object).

This means that you can't really learn enough about the structure of the rest service by looking at JSON strings it accepts or sends. You need to look at the documentation or the internal objects which the service uses to parse the JSON instead.

Example:

 {"foo":"bar"}

That tells you that the REST service accepts a JavaScript object and one of the possible parameters. But it doesn't tell you about the other 50 parameters.

If you only have the JSON, then you can use a parsing library to turn that into something that you can print. But unless you want pretty printing (indent and such), that's the same as printing the JSON string itself, so you don't gain anything.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820