I am parsing the json .I am checking json array and after that make another object .I just struck in one place.Actually I am checking that if parent have child I add one object in "testCaseList "array that against child .But I need to check if child id have character "not" it should add in this array "commandList"
http://jsfiddle.net/tJ7Kq/5/
Here is my input .
[
{
"id": "a",
"text": "a",
"icon": true,
"li_attr": {
"id": "a"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
]
},
{
"id": "b",
"text": "b\n ",
"icon": true,
"li_attr": {
"id": "b"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
{
"id": "b-a-1",
"text": "b-a",
"icon": true,
"li_attr": {
"id": "b-a-1"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
]
},
{
"id": "b-b-2",
"text": "b-b\n ",
"icon": true,
"li_attr": {
"id": "b-b-2"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
{
"id": "b-b-a",
"text": "b-b-a",
"icon": true,
"li_attr": {
"id": "b-b-a"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
]
},
{
"id": "b-b-b",
"text": "b-b-b",
"icon": true,
"li_attr": {
"id": "b-b-b"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
]
}
]
}
]
},
{
"id": "c-1",
"text": "c\n ",
"icon": true,
"li_attr": {
"id": "c-1"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
{
"id": "not-c-a-1",
"text": "c-a",
"icon": true,
"li_attr": {
"id": "not-c-a-1"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
]
},
{
"id": "not-c-b-2",
"text": "b-b",
"icon": true,
"li_attr": {
"id": "not-c-b-2"
},
"a_attr": {
"href": "#"
},
"state": {
"loaded": true,
"opened": false,
"selected": false,
"disabled": false
},
"data": {
},
"children": [
]
}
]
}
]
getting out put this
[
{
"a": {
"commandList": [],
"testCaseList": []
}
},
{
"b": {
"commandList": [],
"testCaseList": [
{
"b-a-1": {
"commandList": [],
"testCaseList": []
}
},
{
"b-b-2": {
"commandList": [],
"testCaseList": [
{
"b-b-a": {
"commandList": [],
"testCaseList": []
}
},
{
"b-b-b": {
"commandList": [],
"testCaseList": []
}
}
]
}
}
]
}
},
{
"c-1": {
"commandList": [],
"testCaseList": [
{
"not-c-a-1": {
"commandList": [],
"testCaseList": []
}
},
{
"not-c-b-2": {
"commandList": [],
"testCaseList": []
}
}
]
}
}
]
Expected out put is :
[
{
"a": {
"commandList": [],
"testCaseList": []
}
},
{
"b": {
"commandList": [],
"testCaseList": [
{
"b-a-1": {
"commandList": [],
"testCaseList": []
}
},
{
"b-b-2": {
"commandList": [],
"testCaseList": [
{
"b-b-a": {
"commandList": [],
"testCaseList": []
}
},
{
"b-b-b": {
"commandList": [],
"testCaseList": []
}
}
]
}
}
]
}
},
{
"c-1": {
"commandList": [
{
"not-c-a-1": {
"commandList": [],
"testCaseList": []
}
},
{
"not-c-b-2": {
"commandList": [],
"testCaseList": []
}
}],
"testCaseList": []
}
}
]