As a beginner I am struggling to find a starting point with my problem:
I am retrieving data in json format through API calls. It is geo data of a given location and the result looks something like this:
{
"version": 0.6,
"generator": "Overpass API 0.7.59.4 36d058c8",
"osm3s": {
"timestamp_osm_base": "2023-03-31T20:39:54Z",
"copyright": "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
},
"elements": [
{
"type": "node",
"tags": {
"amenity": "parking_space",
"capacity": "1",
"parking_space": "disabled"
}
},
{
"type": "way",
"tags": {
"electrified": "contact_line",
"frequency": "50",
"gauge": "1435",
"maxspeed": "90",
"operator": "DB",
"passenger_lines": "2",
"railway": "rail",
"railway:etcs": "1",
"ref": "1",
"tracks": "2",
"usage": "main",
"voltage": "25000"
}
},
{
"type": "way",
"tags": {
"building": "house",
"source": "bing"
}
},
{
"type": "way",
"tags": {
"landuse": "residential",
"name": "Pfaffental"
}
},
{
"type": "way",
"tags": {
"access": "private",
"leisure": "garden"
}
},
{
"type": "way",
"tags": {
"landuse": "railway",
"layer": "1",
"man_made": "bridge"
}
},
{
"type": "way",
"tags": {
"natural": "cliff"
}
},
Now I want to parse all values of all tags into a single list of strings (“parking_space”, “1”, “disabled”, …) or alternatively a dictionary with key:value pairs (“amenity”:“parking_space”, “capacity”: “1”, …) in order to search for specific keywords from the results.
I’ve been researching far and wide how to correctly parse/deserialize json in unity and almost always the answer was to create an object. Considering the format I get the data in, I would get multiple objects (depending on the API response can be over 50) with each a list/dictionary of existing tags and thats quite complicated to handle. Is there a better solution to this if I don’t need any other data than the values of the tags from the API response?
I also read that the Unity Json.Utility cannot parse into a dictionary so tried to find Info on how to do it with Json.NET but couldnt figure it out. Besides, if I understood correctly a dictionary must have unique keys, so with duplicates like eg. “landuse”: “residential” and “landuse”: “railway” it will not work, right? How can i parse the values of the tags into a list instead?
I am very grateful for any suggestion or explanation on how to extract the needed data!