Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
String to non-array json

I have a string that looks like the following:

 {
  "results": [
    {
      "address_components": [
        {
          "long_name": "Ireland",
          "short_name": "Ireland",
          "types": [
            "establishment",
            "natural_feature"
          ]
        }
      ],
      "formatted_address": "Ireland",
      "geometry": {
        "bounds": {
          "northeast": {
            "lat": 55.38294149999999,
            "lng": -5.431909999999999
          },
          "southwest": {
            "lat": 51.4475448,
            "lng": -10.4800237
 

         }
            }],
    "status" : "OK"
   }

I want to turn this into a json that I can easily traverse. However when I call JSON.parse() on this string I get a json array that is a pain to traverse. I want to be able to extract the lat and lng from northeast without having to loop through the entire array.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 var json = `{
    "results": [
        {
            "address_components": [
                {
                    "long_name": "Ireland",
                    "short_name": "Ireland",
                    "types": [
                        "establishment",
                        "natural_feature"
                    ]
                }
            ],
            "formatted_address": "Ireland",
            "geometry": {
                "bounds": {
                    "northeast": {
                        "lat": 55.38294149999999,
                        "lng": -5.431909999999999
                    },
                    "southwest": {
                        "lat": 51.4475448,
                         "lng": -10.4800237
                    }
                }
            }
        }
   ],
   "status" : "OK"
}`;
var data = JSON.parse(json);
var bounds = data.results[0].geometry.bounds;
var bound = bounds.northeast || bounds.southwest;
console.log(bound.lat, bound.lng);

If you know northeast is always an option you can simplify this to:

console.log(data.results[0].geometry.bounds.northeast);

That will give you your lat and lng.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!