Please use the pre-formatted text option in the editor when pasting code or JSON, so everything doesn’t end up aligned to the left.
{
"post code": "12345",
"country": "United States",
"country abbreviation": "US",
"places": [
{
"place name": "Schenectady",
"longitude": "-74.058",
"state": "New York",
"state abbreviation": "NY",
"latitude": "42.8333"
},
{
"post code": "90210",
"country": "United States",
"country abbreviation": "US",
"places": [
{
"place name": "Beverly Hills",
"longitude": "-118.4065",
"state": "California",
"state abbreviation": "CA",
"latitude": "34.0901"
}
]
},
{
"post code": "B2R",
"country": "Canada",
"country abbreviation": "CA",
"places": [
{
"place name": "Waverley",
"longitude": "-63.5144",
"state": "Nova Scotia",
"state abbreviation": "NS",
"latitude": "44.7431"
}
]
}
]
}
Can you please check\correct the JSON as it doesn’t look right.
Please correct the JSON, and I’ll help with the searching the outer objects for the relevant object.
If I’m reading this right this will be a bit more of a challenge, as the post code and country is outside of the places array, so you can’t use the JavaScript find or filter functions (which only works against arrays).
Make sure you copy the response fully. I need to know how the response starts and whether it really starts with an object, or if it actually is an array which I would have thought it should be. It just doesn’t look right at all.
Use a JSON validator if necessary.
Can you please confirm if it is possible for a post code and country to have multiple places in the response. Places is an array, so I’m guessing it could have multiple places? If this is the case, then you should provide a sample response with a record that has multiple places so the logic can be tested properly.