Get key value from nested json

I have a (nested) data structure containing objects and arrays. How can I extract information, that is, access specific or multiple values ​​using a known key?

For instance:

var data = { code: 42, items: [{ id: 1, category: [{ cId: 1, prodname: 'foo', quality: [{ qId: 012, testName: 'micro' }, { qId: 013, testName: 'nano' }] }, { id: 2, prodname: 'bar' }] }] }; 

How do I access the quality key?

Note This is an example of a JSON object; an object is dynamically generated; this is an unknown depth.

+4
source share
1 answer

In this way:

 data.items[ 0 ].category[ 0 ].quality; > [ Object, Object ] 
+2
source

Source: https://habr.com/ru/post/1494218/


All Articles