{"id":1317,"date":"2022-08-30T15:15:31","date_gmt":"2022-08-30T15:15:31","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/10\/searching-in-a-multidimensional-json-object-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:15:31","modified_gmt":"2022-08-30T15:15:31","slug":"searching-in-a-multidimensional-json-object-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/searching-in-a-multidimensional-json-object-collection-of-common-programming-errors\/","title":{"rendered":"Searching in a multidimensional json object-Collection of common programming errors"},"content":{"rendered":"<p>I thought this was going to be easy, but it&#8217;s turning into quite a headache. I have a multidimensional JSON object being returned from my webserver. I&#8217;m parsing it to build a fairly deep navigation pane. I need to be able to search this object, but I&#8217;m coming up blank for the means.<\/p>\n<p>The object is structured as so: tree-&gt;rows[]=&gt;tree-&gt;rows[]=&gt;tree \u2026<\/p>\n<p>Each tree can have many rows, and each row can have a tree etc.<\/p>\n<p>At the row level there are a few variables, I need to search and find the value of one. EX: <code>if(tree.rows[x].tree.rows[y].url ==\"http:\/\/stackoverflow.com\" return true;<\/code><\/p>\n<p>My difficulty is, I don&#8217;t know how to traverse the whole object. Even if I do it recursively I don&#8217;t know how I could keep going up and down all the rows.<\/p>\n<p>Here&#8217;s an example of the object:<\/p>\n<pre><code>var jsonLNav = {itemClassName:\"NodeLink\",linkClassName:\"NodeLinkTitle\",linkHideClassName:\"HideFromProd\",navCategoryClassName:\"NavCategory\",onLoadJS:\"\",tree:[{pos:1,wid:\"263a97c2-7cb9-470c-bf86-cadc28ae1323\",pid:\"1\",rows:[{hide:0,title:\"More IT Help\",isNC:0,isMig:0,url:\"http:\/\/vm-hsspdv-d09p\/en-us\/Help\/Pages\/ITHelp.aspx\",isOL:0,tree:{pos:2,wid:\"263a97c2-7cb9-470c-bf86-cadc28ae1323\",pid:\"3\"}},{hide:0,title:\"Office 2010\",isNC:0,isMig:1,url:\"http:\/\/office2010.lmig.com\/Pages\/Default.aspx\",isOL:0,tree:{pos:2,wid:\"263a97c2-7cb9-470c-bf86-cadc28ae1323\",pid:\"9\"}},{hide:0,title:\"E-mail Management\",isNC:0,isMig:0,url:\"http:\/\/vm-hsspdv-d09p\/en-us\/Help\/EmailManagement\/Pages\/default.aspx\",isOL:0,tree:{pos:2,wid:\"8be66348-8da1-4e5c-90c5-0930d2f52d1a\",pid:\"123\"}},]}]}; \n<\/code><\/pre>\n<p>This example piece doesn&#8217;t have any child trees of the row, the object that does is tens of thousands characters long, I can post if necessary.<\/p>\n<p>The best code I can think of would be close to this (not tested, conceptually I&#8217;m missing something):<\/p>\n<pre><code>function findURL(url)\n{\n\nalert(searchJson(jsonLNav.tree[0],url));\n}\/\/end findURL\n\nfunction searchJson(tree,url)\n{\n\nfor(var x=0; x<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-10 00:16:34. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I thought this was going to be easy, but it&#8217;s turning into quite a headache. I have a multidimensional JSON object being returned from my webserver. I&#8217;m parsing it to build a fairly deep navigation pane. I need to be able to search this object, but I&#8217;m coming up blank for the means. The object [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1317","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1317"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1317\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}