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

163
Views
How to access second level in json object?

This is JSON object

{
 "key": "***************",
"****************": {
 "comment": "hello" 
}
"text": "world"
}

I want to return comment field, how?

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

0

Try item[item.key].comment to access it

Edited based on Stephen Ostermiller comment.

Lets say you have a variable like this:

let item = {
  "key": "someDynamicString",
  "someDynamicString": {
    "comment": "hello" 
  }
  "text": "world"
}

You can access the value of key property by either

item.key

or

item["key"]

both of those will return the value of item.key which is "someDynamicString"

The latter option can be use to access object property which have dynamic key. Let say that "someDynamicString" key is not always "someDynamicString", but dynamically change based on item.key.

You can access that dynamic key with item[item.key] which is equal to item["someDynamicString"] and item.someDynamicString

so whatever the item.key value is, you can always access the second level in json object you asked about.

Furthermore, to access comment property inside the dynamic key: item[item.key].comment

Further explanation: Dynamically access object property using variable

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!