javascript - Get json substring using a particular object node name -


i have json string this. part of json string.

                                "foldchildren": "false",                                 "branchcolor": "#000000",                                 "children": [                                     {                                         "id": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",                                         "parentid": "211c838e-3e2d-4919-ab09-dd7f8a901b97",                                         "text": {                                             "caption": "f",                                             "font": {                                                 "style": "normal",                                                 "weight": "normal",                                                 "decoration": "none",                                                 "size": "15",                                                 "color": "#000000"                                             }                                         },                                         "offset": {                                             "x": "30",                                             "y": "93"                                         },                                         "foldchildren": "false",                                         "branchcolor": "#000000",                                         "children": {                                             "id": "2ecaecb6-d55c-4203-bace-f14e276700af",                                             "parentid": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",                                             "text": {                                                 "caption": "x",                                                 "font": {                                                     "style": "normal",                                                     "weight": "normal",                                                     "decoration": "none",                                                     "size": "15",                                                     "color": "#000000"                                                 }                                             },                                             "offset": {                                                 "x": "122",                                                 "y": "114"                                             },                                             "foldchildren": "false",                                             "branchcolor": "#000000",                                             "children": ""                                         }                                     }, 
  • what need find first node object name "children" , string inside children object.

    expected output first step

    [                             {                                 "id": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",                                 "parentid": "211c838e-3e2d-4919-ab09-dd7f8a901b97",                                 "text": {                                     "caption": "f",                                     "font": {                                         "style": "normal",                                         "weight": "normal",                                         "decoration": "none",                                         "size": "15",                                         "color": "#000000"                                     }                                 },                                 "offset": {                                     "x": "30",                                     "y": "93"                                 },                                 "foldchildren": "false",                                 "branchcolor": "#000000",                                 "children": {                                     "id": "2ecaecb6-d55c-4203-bace-f14e276700af",                                     "parentid": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",                                     "text": {                                         "caption": "x",                                         "font": {                                             "style": "normal",                                             "weight": "normal",                                             "decoration": "none",                                             "size": "15",                                             "color": "#000000"                                         }                                     },                                     "offset": {                                         "x": "122",                                         "y": "114"                                     },                                     "foldchildren": "false",                                     "branchcolor": "#000000",                                     "children": ""                                 }                             }, 
  • now need next node object name "children" json string got first step. expected output after second step

      {                             "id": "2ecaecb6-d55c-4203-bace-f14e276700af",                             "parentid": "3f67cbab-ff5a-4f61-b1ef-d551271e8af2",                             "text": {                                 "caption": "x",                                 "font": {                                     "style": "normal",                                     "weight": "normal",                                     "decoration": "none",                                     "size": "15",                                     "color": "#000000"                                 }                             },                             "offset": {                                 "x": "122",                                 "y": "114"                             },                             "foldchildren": "false",                             "branchcolor": "#000000",                             "children": ""                         }                     }, 
  • and on till string ends.

it sounds want find "children" node on given json structure, in case can depth-first search traverse entire json structure.

check out other stackoverflow post: how recursive search of javascript/json tree?


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -