How to use 'json find' in JavaScript

Every line of 'json find' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
277function json_find_key(json, key) {
278 if (key in json) {
279 return json[key];
280 }
281
282 for (var k in json) {
283 if (type(json[k]) == 'Object' || type(json[k]) == 'm.Map') {
284 var o = json_find_key(json[k], key);
285 if (o != undefined)
286 return o;
287 } else if (type(json[k]) == 'Array' || type(json[k]) == 'm.Array') {
288 for (var i in json[k]) {
289 if (type(json[k][i]) != "String") {
290 var o = json_find_key(json[k][i], key);
291 if (o != undefined)
292 return o;
293 }
294 }
295 }
296 }
297
298 return undefined;
299}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code


Related snippets