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

121
Views
Parse value only from JSON string

An API returns a string of text that looks like this (xxx used for security):

{"xxx":{"xxx":{"xxx":{"xxx":{"results":[{"latest.GigabytesIngested":12641.824682336}]}}}}}

If I do this:

console.log(JSON.parse(body).xxx.xxx.xxx.xxx.results[0]);

I get this, which is fine:

{ 'latest.GigabytesIngested': 12641.82487968 }

My problem is I only want to grab the number. The below attempt doesn't work, maybe because there's a dot in the key name, or maybe because I'm just doing it wrong?

console.log(JSON.parse(body).xxx.xxx.xxx.xxx.results[0].latest.GigabytesIngested);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Yes, the period in the key is the problem. You need to use an alternate way to reference the key.

console.log(JSON.parse(body).xxx.xxx.xxx.xxx.results[0]["latest.GigabytesIngested"]);

or

var result = JSON.parse(body).xxx.xxx.xxx.xxx.results[0];
var lgi = result["latest.GigabytesIngested"];
console.log(lgi);
about 4 years ago · Juan Pablo Isaza Report

0

@derpirscher answered correctly in a comment:

console.log(JSON.parse(body).data.actor.account.nrql.results[0]['latest.GigabytesIngested']);
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!