I'm not able to get this code working:
$paths = ['2014/','2014/04/','2015/'];
$tree = array();
foreach ($paths as $path) {
$dir_exploded = explode("/", $path);
array_pop($dir_exploded);
$tmp = array();
for ($i = count($dir_exploded) - 1; $i >= 0; $i--) {
if ($i == count($dir_exploded) - 1) {
$children = array();
} else {
$children = array($tmp);
}
$tmp = array('text' => $dir_exploded[$i], 'children' => $children);
}
$tree = array_replace_recursive($tree, $tmp);
}
echo(json_encode(array(array('text' => '/', 'children' => array($tree)))));
I get:
[
{
"text": "/",
"children": [
{
"text": "2015",
"children": [
{
"text": "04",
"children": []
}
]
}
]
}
]
So 2014 have been delete by the merge of this 2 arrays. I would like to get:
[
{
"text": "/",
"children": [
{
"text": "2014",
"children": [
{
"text": "04",
"children": []
}
]
},{
"text": "2015",
"children": []
}
]
}
]
At least I want to send this tree by json using json_encode, or a better way if you know one.
Try this code, I have change little code of yours and add some extra paths.
$paths = array('2014/', '2014/04/','2014/03/','2015/');
$new_tree = $temp_new_tree = array();
foreach ($paths as $path)
{
$dir_exploded = explode("/", $path);
array_pop($dir_exploded);
$temp_new_tree = (!empty($new_tree)) ? $new_tree : array();
$tmp = $tree = array();
for ($i = count($dir_exploded) - 1; $i >= 0; $i--)
{
if ($i == count($dir_exploded) - 1) {
$children = array();
} else {
$children = array($tmp);
}
$tmp = array('text' => $dir_exploded[$i], 'children' => $children);
}
$tree = array_replace_recursive($tree, $tmp);
$new_tree[$dir_exploded[0]] = $tree;
if(array_key_exists($dir_exploded[0], $temp_new_tree))
{
$new_tree[$dir_exploded[0]]['children'] = array_merge($new_tree[$dir_exploded[0]]['children'], $temp_new_tree[$dir_exploded[0]]['children']);
}
}
//echo json_encode(array(array('text' => '/', 'children' => array($new_tree))));
$new_tree = array_shift(array_chunk($new_tree, count($new_tree)));
echo json_encode(array(array('text' => '/', 'children' => $new_tree)));
Output will be like this:--
[
{
text: "/",
children: [
{
text: "2014",
children: [
{
text: "03",
children: [ ]
},
{
text: "04",
children: [ ]
}
]
},
{
text: "2015",
children: [ ]
}
]
}
]
Hope this will help you...
You can use following;
<?php
$paths = array('2014/01/02','2014/04/03','2015/07');
$all = array();
foreach ($paths as $path) {
$temp = explode("/", $path);
$all[] = tree($temp, 0);
}
var_dump($all);
function tree($arr, $i) {
if (count($arr) == ($i + 1)) return $arr[$i];
return array(
"text" => $arr[$i],
"children" => tree($arr, $i+1)
);
}
Here is a working demo: codepad
Related
I have a CSV data looks like this :
ps.csv
id|firstName|lastName|address|extId|extName
001|Kapil|Parames|address01|AA01|AA
002|David|Vuitton|address01|AA02|AA
002|David|Vuitton|address02|BB02|BB
003|Jean|Paul|address01|AA03|AA
And i need an output JSON to look like this :
[
{
"id": "001",
"firstName": "Kapil",
"lastName": "Parames",
"address": [{
"address": "address01"
}],
"ext": [{
"extId": "AA01",
"extName": "AA"
}]
},
{
"id": "002",
"firstName": "David",
"lastName": "Vuitton",
"address": [{
"address": "address01"
},
{
"address": "address02"
}
],
"ext": [{
"extId": "AA02",
"extName": "AA"
},
{
"extId": "BB02",
"extName": "BB"
}
]
},
{
"id": "003",
"firstName": "Jean",
"lastName": "Paul",
"address": [{
"address": "address01"
}],
"ext": [{
"extId": "AA03",
"extName": "AA"
}]
}
]
I can convert it to JSON. But the problem is i would like to add "address" and "extId", "extName" into multi level array if the person already exists in the list.
So following PHP code is working for me :
$csv = file('ps.csv');
$csvArray = [];
foreach ($csv as $line) {
$csvArray[] = str_getcsv($line, '|', ',');
}
$jsonArray = [];
for ($i = 1; $i < count($csvArray); $i++) {
$found = -1;
for ($j = 0; $j < count($jsonArray); $j++) {
if (in_array($csvArray[$i][0], $jsonArray[$j])) {
$found = $j;
}
}
if ($found < 0) {
$jsonArray[] = array(
'id' => $csvArray[$i][0],
'firstName' => $csvArray[$i][1],
'lastName' => $csvArray[$i][2],
'address' => array(
[
'address' => $csvArray[$i][3]
]
),
'ext' => array(
[
'extId' => $csvArray[$i][4],
'extName' => $csvArray[$i][5]
]
)
);
} else {
$addressArray = array(
'address' => $csvArray[$i][3]
);
$extArray = array(
'extId' => $csvArray[$i][4],
'extName' => $csvArray[$i][5]
);
array_push($jsonArray[$found]['address'], $addressArray);
array_push($jsonArray[$found]['ext'], $extArray);
}
}
echo '<pre>';
echo json_encode($jsonArray, JSON_PRETTY_PRINT);
echo '</pre>';
Is that correct or is there any other way to do ?
I wrote some PHP code to line up the children of an array. I wrote a recursive function.
Everything is listed correctly one below the other, but some arrays do not have the "Name" key.
Does anyone have any idea how I can get it to show everyone's "Name" key?
My PHP Code:
$json = '[
{
"name": "A",
"children": [
{
"name": "B",
"children": [
{
"name": "C"
},
{
"name": "D",
"children": [
{
"name": "E"
},
{
"name": "F"
}
]
}
]
},
{
"name": "G"
}
]
},
{
"name": "H"
}
]';
header('Content-Type: application/json; charset=utf-8');
$json = json_decode($json, true);
function array_flatten($array, $prefix = '') {
$return = array();
foreach ($array as $key => $value) {
if (is_array($value) && array_key_exists("children", $value)){
$return = array_merge($return, array_flatten($value, $key));
}else if (is_array($value) && count($value) > 1){
foreach ($value as $keyA => $valueA) {
if (is_array($valueA) && array_key_exists("children", $valueA)){
$return = array_merge($return, array_flatten($valueA, $keyA));
}else{
$return[] = $valueA;
}
}
} else {
$return[] = $value;
}
}
return $return;
}
echo json_encode(array_flatten($json));
Current Result:
["A","B",{"name":"C"},"D",{"name":"E"},{"name":"F"},{"name":"G"},{"name":"H"}]
What I want:
[{"name":"A"},{"name":"B"},{"name":"C"},{"name":"D"},{"name":"E"},{"name":"F"},{"name":"G"},{"name":"H"}]
Here is a working code :
<?php
$json = '[
{
"name": "A",
"children": [
{
"name": "B",
"children": [
{
"name": "C"
},
{
"name": "D",
"children": [
{
"name": "E"
},
{
"name": "F"
}
]
}
]
},
{
"name": "G"
}
]
},
{
"name": "H"
}
]';
$json = json_decode($json, true);
function getArrayValuesRecursively(array $array){
$values = [];
foreach ($array as $value) {
if (is_array($value)) {
$values = array_merge(
$values,
getArrayValuesRecursively($value)
);
} else {
$values[] = ['name' => $value];
}
}
return $values;
}
echo json_encode(getArrayValuesRecursively($json));
Demo : https://3v4l.org/01Fla
Function getArrayValuesRecursively(array $array) is from Get all values from multidimensional array
here's my take on it:
$json = json_decode($json, true);
$names = get_names_of_people($json);
print(json_encode($names));
function get_names_of_people(array $people): array
{
$names = [];
foreach ($people as $person) {
foreach ($person as $key => $value) {
switch ($key) {
case 'name':
$names[] = [
'name' => $value,
];
break;
case 'children':
$names = array_merge($names, get_names_of_people($value));
}
}
}
return $names;
}
$array = json_decode($json, true);
$result = [];
array_walk_recursive($array, function ($value, $key) use(&$result) {
$result[][$key] = $value;
});
I have tried to handle JSON responses with a complex structure and I don't know how to manage it after multiple attempts.
The JSON response must be like this:
"note": {
"vote": 3,
"items":[
{
"value": 1,
"touchArea": {
"x": 122,
"y": 173,
"w": 89,
"h": 89
}
},
{
"value": 2,
"touchArea": {
"x": 122,
"y": 283,
"w": 89,
"h": 89
}
},
{
"value": 3,
"touchArea": {
"x": 122,
"y": 390,
"w": 89,
"h": 89
}
}
]
Note: 'vote' is the max value of the array
As source, i request MYSQL and i get this array ($touch) :
Array ( [0] => V:1,X:122,Y:173,W:89,H:89 [1] => V:2,X:122,Y:283,W:89,H:89 [2] => V:3,X:122,Y:390,W:89,H:89 )
My question is : How to generate this JSON response from PHP with loops, in this example we have only 3 values, but it could be more.
You can use the following to edit and re-save your data from and to json file or string.
<?php
$sInFile = 'in2.json';
$sOutFile = 'out2.json';
$aDevelopers = array();
$aArtists = array();
$aCooks = array();
$sRaw = file_get_contents( $sInFile );
var_dump( $sRaw );
// object
$oData = json_decode( $sRaw );
//array
$aData = json_decode( $sRaw, 1 );
$aNote = $aData[ 'note' ];
$aItems = $aNote[ 'items' ];
var_dump( $aData );
$iCountData = count( $aItems );
// Loops through items and set new values.
for( $i = 0; $i < $iCountData; ++$i )
{
$aItem = $aItems[ $i ];
$aItem[ 'value' ] = 'newvalue';
$aItem[ 'touchArea' ][ 'x' ] = 3455;
$aItem[ 'touchArea' ][ 'y' ] = 43;
$aItems[ $i ] = $aItem;
}
$aNote[ 'items' ] = $aItems;
$aData[ 'note' ] = $aNote;
var_dump( $aData );
$sNewJson = json_encode( $aData );
file_put_contents( $sOutFile, $sNewJson );
?>
Assuming that your result set from MySQL is an array of strings, as implied in your question, you'll need to iterate over this result set, split the string on , and then on :, before massaging the data into the structure you want, before finally converting to json.
The following should work for you given the information you have provided:
<?php
// your initial result set from mysql - an array of strings
$touch = [
'V:1,X:122,Y:173,W:89,H:89',
'V:2,X:122,Y:283,W:89,H:89',
'V:3,X:122,Y:390,W:89,H:89',
];
// map over each element in your result set...
$items = array_map(function($item) {
$array = [];
// first, break each string on `,` to
// get an array of elements; e.g:
// ['V:1', 'X:122', 'Y:173', 'W:89', 'H:89'] etc.
$itemElements = explode(',', $item);
// then, iterate over these elements...
foreach ($itemElements as $itemElement) {
// explode on `:` and assign as a key value pair
list($key, $value) = explode(':', $itemElement);
// then, check the key and add the
// value to the array as appropriate
if ('V' === $key) {
$array['value'] = $value;
} else {
$array['touchArea'][strtolower($key)] = $value;
}
}
return $array;
}, $touch);
// then, build the `$note` array...
$note = [
'note' => [
'vote' => count($items),
'items' => $items,
]
];
// finally, json encode
echo json_encode($note, JSON_PRETTY_PRINT);
This yields:
{
"note": {
"vote": 3,
"items": [
{
"value": "1",
"touchArea": {
"x": "122",
"y": "173",
"w": "89",
"h": "89"
}
},
{
"value": "2",
"touchArea": {
"x": "122",
"y": "283",
"w": "89",
"h": "89"
}
},
{
"value": "3",
"touchArea": {
"x": "122",
"y": "390",
"w": "89",
"h": "89"
}
}
]
}
}
Hope this helps :)
Solution with array_map, explode, array_column and max functions:
$touch = ["V:1,X:122,Y:173,W:89,H:89", "V:2,X:122,Y:283,W:89,H:89", "V:3,X:122,Y:390,W:89,H:89"];
$result_arr = ["note" => ["vote" => 0, "items" => []]]; // basic structure
array_map(function($v) use (&$result_arr){
$arr = explode(",", $v);
$result = [];
foreach ($arr as $value) {
$new_arr = explode(":", $value);
$key = strtolower($new_arr[0]);
if ($key == "v"){
$result["value"] = $new_arr[1];
} else {
$result["touchArea"][$key] = $new_arr[1];
}
}
$result_arr["note"]["items"][] = $result;
}, $touch);
// getting max vote
$result_arr["note"]["vote"] = max(array_column($result_arr["note"]["items"], "value"));
$final_json = json_encode($result_arr, JSON_PRETTY_PRINT);
I can't get my json_encode format that I need.
Current Format:
{
"substantiv": [
{"text":"auto"},
{"text":"noch ein auto"}
],
"verben":[
{"text":"auto fahren"}
]
}
What I need:
[
{
"type":"substantiv",
"items": [
{"text":"auto"},
{"text":"noch ein auto"}
]
} , {
"type":"verben",
"items": [
{"text":"auto fahren"}
]
}
]
My current php code:
$data = array();
while($row = $rs->fetch_assoc()){
$tmp = array(
"text" => $row['gtext']
);
$data[$row['type']][] = $tmp;
}
echo json_encode($data);
I have tried a few things but just can't figure it out.
You could try something like this
while($row = $rs->fetch_assoc()){
$data[$row['type']][] = array(
"text" => $row['gtext']
);
}
$result = array();
foreach($data AS $type => $items) {
$result[] = array(
'type' => $type,
'items' => $items
);
}
echo json_encode($result);
What you actually want is this:
[
{
"type": "substantiv",
"items": [
{
"text": "auto"
},
{
"text": "noch ein auto"
}
]
},
{
"type": "verben",
"items": [
{
"text": "auto fahren"
}
]
}
]
which is the output you'll get from Louis H.'s answer's code.
I need a help. I'm looking for a solution for this problem!
I have a file which contains the following pattern:
Brazil|SaoPaulo|Diadema|RuadaFe Brazil|SaoPaulo|Diadema|RuadoLimoeiro
Brazil|SaoPaulo|SaoCaetano|RuadasLaranjeiras
Brazil|Parana|Curitiba|ComendadorAraujo
USA|NewJersey|JerseyCity|WhashingtonBoulervard
USA|NewJersey|JerseyCity|RiverCourt
Which should bring after some array key implementation, something like this (after apply json_encode call on php):
{
"name": "Brazil",
"children": [
{
"name": "SaoPaulo",
"children": [
{
"name": "Diadema",
"children": [
{"name": "RuadaFe"},
{"name": "RuadoLimoeiro"}
]
},
{
"name": "SaoCaetano",
"children": [
{"name": "RuadasLaranjeiras"}
]
},
]
"name": "Parana",
"children": [
{
"name": "Curitiba",
"children": [
{"name": "ComendadorAraujo"}
]
}
]
},
"name":"USA",
"children":[
{
"name": "NewJersey",
"children": [
{
"name": "JerseyCity",
"children": [
{"name": "WhashingonBoulevard"},
{"name": "RiverCourt"}
]
}
]
}
]
}
]
And keep going and going (and even more deeper too).
Please, help me team... thanks in advance.
Here what I get until now:
Array
(
[Brazil] => Array
(
[SaoPaulo] => Array
(
[Diadema] => Array
(
[RuadoLimoeiro] =>
)
[SaoCaetano] => Array
(
[RuadasLaranjeiras] =>
)
)
[Parana] => Array
(
[Curitiba] => Array
(
[ComendadorAraujo] =>
)
)
)
[USA] => Array
(
[NewJersey] => Array
(
[JerseyCity] => Array
(
[WhashingtonBoulervard] =>
[RiverCourt] =>
)
)
)
)
And here is the json encoded:
{
"Brazil":{
"SaoPaulo":
{"Diadema":
{"RuadoLimoeiro":null},
"SaoCaetano":{"RuadasLaranjeiras":null}
},
"Parana":
{"Curitiba":
{"ComendadorAraujo":null}
}
},
"USA":{
"NewJersey":{
"JerseyCity":{
"WhashingtonBoulervard":null,
"RiverCourt":null}
}
}
}
As you can see, the "names" and "child" is missing because is not an array key structure, also something is wrong, because I'm missing some values on SaoPaulo.
Here is the function:
foreach($strings as $string) {
$parts = array_filter(explode('|', $string));
$ref = &$result;
foreach($parts as $p) {
// echo $p;
if(!isset($ref[$p])) {
$ref[$p] = array();
// $ref[$p] = array("name"=>$p);
}
$ref = &$ref[$p];
}
$ref = null;
}
-------------------------------- AFTER SOME ANSWERS --------------------------
{
"name": "Brazil(country)",
"children": [
{
"name": "SaoPaulo(state)", // only one state
"children": [
{
"name": "Diadema(city)", // only one city
"children": [
{"name": "RuadaFe(street)"}, // two streets under the same city...
{"name": "RuadoLimoeiro(street)"}
]
},
{
"name": "SaoCaetano(city)",
"children": [
{"name": "RuadasLaranjeiras(street)"}
]
},
]
"name": "Parana(state)",
"children": [
{
"name": "Curitiba(city)",
"children": [
{"name": "ComendadorAraujo(street)"}
]
}
]
},...
I put on parentesis the structure (country, state, city, street) just to clarify what i want.
Got it?
It is not outright trivial, but what I did is actually the same as you (the same way as in your edited question), but I also keep track of those arrays to rename the keys. And that's what I do afterwards then:
$separator = [' ', '|'];
$buffer = file_get_contents($file);
$entries = explode($separator[0], $buffer);
$result = [];
$named[] = &$result;
########
foreach ($entries as $entry) {
$each = explode($separator[1], $entry);
$pointer = & $result;
while ($current = array_shift($each)) {
if (!isset($pointer[$current])) {
unset($children);
$children = [];
$named[] = &$children;
########
$pointer[$current] = ['name' => $current, 'children' => &$children];
}
$pointer = & $pointer[$current]['children'];
}
}
foreach($named as $offset => $namedArray) {
$keys = array_keys($namedArray);
foreach($keys as $key) {
$named[$offset][] = &$namedArray[$key];
unset($named[$offset][$key]);
}
}
print_r($result);
See it in action.
You probably might want to modify this by checking in the later foreach if children are empty (leaf-nodes) and then removing the children entry as well.
Here the modified foreach at the end and json output:
foreach($named as $offset => $namedArray) {
$keys = array_keys($namedArray);
foreach($keys as $key) {
if (!$namedArray[$key]['children']) {
unset($namedArray[$key]['children']);
}
$named[$offset][] = &$namedArray[$key];
unset($named[$offset][$key]);
}
}
echo json_encode($result, JSON_PRETTY_PRINT);
Output:
[
{
"name": "Brazil",
"children": [
{
"name": "SaoPaulo",
"children": [
{
"name": "Diadema",
"children": [
{
"name": "RuadaFe"
},
{
"name": "RuadoLimoeiro"
}
]
},
{
"name": "SaoCaetano",
"children": [
{
"name": "RuadasLaranjeiras"
}
]
}
]
},
{
"name": "Parana",
"children": [
{
"name": "Curitiba",
"children": [
{
"name": "ComendadorAraujo"
}
]
}
]
}
]
},
{
"name": "USA",
"children": [
{
"name": "NewJersey",
"children": [
{
"name": "JerseyCity",
"children": [
{
"name": "WhashingtonBoulervard"
},
{
"name": "RiverCourt"
}
]
}
]
}
]
}
]
The full code-example at a glance:
<?php
/**
* PHP - Nested array keys based on string lines
* #link http://stackoverflow.com/a/16305236/2261774
*/
$file = 'data://text/plain;base64,' . base64_encode('Brazil|SaoPaulo|Diadema|RuadaFe Brazil|SaoPaulo|Diadema|RuadoLimoeiro Brazil|SaoPaulo|SaoCaetano|RuadasLaranjeiras Brazil|Parana|Curitiba|ComendadorAraujo USA|NewJersey|JerseyCity|WhashingtonBoulervard USA|NewJersey|JerseyCity|RiverCourt');
$separator = [' ', '|'];
$buffer = file_get_contents($file);
$entries = explode($separator[0], $buffer);
$result = [];
$named[] = &$result;
foreach ($entries as $entry) {
$each = explode($separator[1], $entry);
$pointer = & $result;
while ($current = array_shift($each)) {
if (!isset($pointer[$current])) {
unset($children);
$children = [];
$named[] = &$children;
$pointer[$current] = ['name' => $current, 'children' => &$children];
}
$pointer = & $pointer[$current]['children'];
}
}
unset($pointer);
foreach($named as $offset => $namedArray) {
$keys = array_keys($namedArray);
foreach($keys as $key) {
if (!$namedArray[$key]['children']) {
unset($namedArray[$key]['children']);
}
$named[$offset][] = &$namedArray[$key];
unset($named[$offset][$key]);
}
}
unset($named);
echo json_encode($result, JSON_PRETTY_PRINT);
your question JSON:
{
"name": "Brazil",
"children": [
{
"name": "SaoPaulo",
"children": [
{
"name": "Diadema",
"children": [
{"name": "RuadaFe"},
{"name": "RuadoLimoeiro"}
]
},
My Answer JSON:
[
{
"name": "Brazil",
"children": [
{
"name": "SaoPaulo",
"children": [
{
"name": "Diadema",
"children": [
{
"name": "RuadaFe"
},
{
"name": "RuadoLimoeiro"
}
]
},
The only difference I can spot is that the root-nodes are wrapped inside an array in my answer, but it should be trivial to fetch them out there if that really is your issue ;)
Does it solves your problem? Use $inputString to put your real string.
<?php
// ------------------------------------------------------ your input goes here ------------------------------------------------------
$inputString = 'Brazil|SaoPaulo|Diadema|RuadaFe Brazil|SaoPaulo|Diadema|RuadoLimoeiro Brazil|SaoPaulo|SaoCaetano|RuadasLaranjeiras Brazil|Parana|Curitiba|ComendadorAraujo USA|NewJersey|JerseyCity|WhashingtonBoulervard USA|NewJersey|JerseyCity|RiverCourt';
class item {
public $name = null;
public function getChildrenByName($strName) {
$ret = null;
# this variable should be defined in interface, but i skipped it so it wont be printed in json when obj does not have childrens
if( !isset( $this->children ) ) {
$this->children = array( );
}
foreach ( $this->children as $child ) {
if( $child->name === $strName ) {
$ret = $child;
break;
}
}
if ( !$ret ) {
$this->children[] = self::spawnByName( $strName );
}
return $this->children[ count($this->children) - 1];
}
static public function spawnByName($strName) {
$ret = new item();
$ret->name = $strName;
return $ret;
}
}
class listManager {
protected $list = array();
public function getList() {
return $this->list;
}
public function addPath( $desiredPath ) {
# path needs to be as array
if ( is_string( $desiredPath ) ) {
$desiredPath = explode('|', $desiredPath);
}
# create root element if it does not already exists
if ( !isset( $this->list[$desiredPath[0]] ) ) {
$this->list[$desiredPath[0]] = item::spawnByName($desiredPath[0]);
}
$curElement = $this->list[$desiredPath[0]];
for( $i=1; $i<count($desiredPath); $i++ ) {
$curElement = $curElement->getChildrenByName( $desiredPath[$i] );
}
}
protected function spawnElement( $strName ) {
$ret = new item();
$ret->name = $strName;
return $ret;
}
}
$output = array();
$expl = explode(' ', $inputString);
$list = new listManager();
foreach ( $expl as $key => $path ) {
$list->addPath( $path );
}
$output = '';
foreach ( $list->getList() as $singleVariable ) {
$output .= json_encode($singleVariable, JSON_PRETTY_PRINT) . ",\n";
}
echo '<pre>'.$output.'</pre>';
?>
Above code produces following json out of your sample code:
{
"name": "Brazil",
"children": [{
"name": "SaoPaulo",
"children": [{
"name": "Diadema",
"children": [{
"name": "RuadaFe"
}
]
}
]
}, {
"name": "SaoPaulo",
"children": [{
"name": "Diadema",
"children": [{
"name": "RuadoLimoeiro"
}
]
}
]
}, {
"name": "SaoPaulo",
"children": [{
"name": "SaoCaetano",
"children": [{
"name": "RuadasLaranjeiras"
}
]
}
]
}, {
"name": "Parana",
"children": [{
"name": "Curitiba",
"children": [{
"name": "ComendadorAraujo"
}
]
}
]
}
]
} {
"name": "USA",
"children": [{
"name": "NewJersey",
"children": [{
"name": "JerseyCity",
"children": [{
"name": "WhashingtonBoulervard"
}
]
}
]
}, {
"name": "NewJersey",
"children": [{
"name": "JerseyCity",
"children": [{
"name": "RiverCourt"
}
]
}
]
}
]
}
edit: changed, does it fit now?