Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda