I have a Table for categories , which stores Hierarchical Data in the following format
NodeID—>ParentID—>NodeName
I want to select categories in the following manner for which i need to return a JSON Object in a predefined format.
JSON FORMAT
"Option 1": {"Suboption":200},
"Option 2": {"Suboption 2": {"Subsub 1":201, "Subsub 2":202},
"Suboption 3": {"Subsub 3":203, "Subsub 4":204, "Subsub 5":205}
}

How do i return JSON in this format from a hierarchical database?? I mean how do i approach?? Kindly show me a direction.
NOTE:
Provided you are in ASP.Net you can just iterate though it using the build in functions:
You can perform iterations using loops as well:
This can be ugly but usable if you have a defined set of levels, if you are performing an Nth dimensional transition it gets very complex very fast.
You can look here for an idea:
Java – Create JSON Object from Multiple Multidimensional Arrays