I have a lot of JSON data which is organized in nested lists. Each list consists of other lists and those lists could contain other lists and so on. The deepest list consists of a pair of longitute and latitude, e.g.
[[[…..[16.353542354,48.2354242424],[16.46353535,48.2546754646]….]…..].
It would look as graph like this:

I basically don’t know how nested those lists are. They differ all the time. The next difficult part is that I need to get “coordinate polygons” from it. That means that the lists that only consist of pairs of coordinates belong to the same polygon. For example:
[……[[16.23542424,48.2342424242],[16.2423242352354,48.12342534634],[16.35353453535,48.345635353]]……
This would mean that there is a polygon consisting of 3 pairs of coordinates (so 3 corners).
I’m sure that this is solvable with some kind of String parsing. I wonder if this is possible with basic JSON.simple (or maybe any other API) possibilities. The problem is that JSON doesn’t know anything about the data it is parsing. I have to tell JSON what the object is and have to use type conversion to get the correct data. See these examples here. Now I need the other way around, but I never know what type is the data (“is it still another list or is the data the pair of coordiantes”), because those lists are very dynamic. How can this be done in a convenient way? I could write some string parsing algorithm with some “push and pop behavior” to compare the JSON string character by character, but I wonder if there isn’t a better way to do this?
[UPDATE]
I figured out that this is a standardized JSON format, called GeoJSON. If you know how to read the data, it’s pretty clear. A Multipolygon consists of Polygons, and Polygons can have holes, represented by a 2nd Array in a Polygon object. See spec:
Polygon, Multipolygon
You know exactly how deeply nested these lists are. At the top of your json, you have:
To me, that implies
List<Polygon>. Now, what’s aPolygon? Well, that’s obviously aList<Coordinate>. Finally, we know aCoordinateis a list with two elements.To conclude, we have
List<List<List<double>>>. The depth of the arrays is known.