Looking to extract values associated with the key text
from a large JSON file. Here is an example snippet:
type":"doc",
"content":[
{
"type":"paragraph",
"content":[
{
"text":"this is a simple page, about a simple umbrella.",
"type":"text"
}
]
},
{
"type":"paragraph",
"content":[
{
"text":"you can use this text to find the umbrella page.",
"type":"text"
}
]
},
{
"type":"paragraph",
"content":[
{
"text":"do you like it?",
"type":"text"
}
]
},
To achieve this without recursion, I am exploring the use of an iterative function instead of Object.keys
. Previous attempts with JSON.stringify
yielded poor performance:
const obj = JSON.parse(content);
let ret = '';
JSON.stringify(obj, (_, nested) => {
if (nested && nested[key]) {
ret += nested[key] + '\n';
}
return nested;
});