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

229
Views
access object paratamters node.js

I am logging a response that I get from the server after sending a post request, and it looks like this:

{"output":"basic question #1. how do I calculate the area of a rectangle based on users input in python?"}

now i want to access output as type plain text (string). I tried this:

 console.log(body)
     //this returns  {"output":"basic question #1. how do I calculate the area of a rectangle based on users input in python?"}
 console.log(JSON.stringify(body))
    //this returns "{\"output\":\"calculate the area of a rectangle based on users input in python\"}"

how would I access output within the body response?

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

0

There is a built-in method called JSON.parse() in JavaScript that will convert JSON to a JavaScript object.


Follow these steps to get the result you want!

  1. Skip if already parsed! First, you need to use JSON.parse() to parse the string JSON into a valid JavaScript object. As a parameter, you pass in the string that you want to parse.

    JSON.parse(body);
    
  2. To access the body, you can either use dot notation or bracket notation. Either one will work; you use them like below.

    // Dot notation
    body.output;
    
    // Bracket notation
    body["output"];
    

The final code should look like this.

const body = `{"output": "Calculate the area of a rectangle based on users input in Python."}`;

const parsed = JSON.parse(body);

// Dot notation
console.log(parsed.output);

// Bracket notation
console.log(parsed["output"]);


In conclusion, the JSON.parse() method built-into JavaScript should help solve the issue.

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!