<?php
$json = '{
"data": {
"card": {
"current_phase": {
"id": "3134719",
"name": "Phase Final"
},
"child_relations": [
{
"cards": [
{
"id": "6405893",
"current_phase": {
"id": "3147728",
"name": "Concluído 2"
},
"child_relations": [
{
"pipe": {
"id": "458138"
},
"name": "Pipe 3 Conexão",
"cards": [
{
"id": "6407049",
"current_phase": {
"id": "3151152",
"name": "pipe 3 phase 1"
}
}
]
}
]
}
]
}
]
}
}
}';
$nivel = 0;
$nivelMax = 0;
$posLim = 0;
for ($i = 0; $i < strlen ($json); $i++) { if ($car == '{') {
$nivel++;
if ($nivel > $nivelMax) {
$nivelMax = $nivel;
$posIniNivelMax = $i;
}
}
if ($car == '}') {
if ($nivel == $nivelMax)
$posFimNivelMax = $i;
$nivel--;
}
if ($car == ',') {
$posLimAnt = $posLim;
$posLim = $i;
}
};
echo substr($json, $posLimAnt+1, $posFimNivelMax - $posLimAnt + 1) . '<br>';
PD9waHAKCiRqc29uID0gJ3sKICAiZGF0YSI6IHsKICAgICJjYXJkIjogewogICAgICAiY3VycmVudF9waGFzZSI6IHsKICAgICAgICAiaWQiOiAiMzEzNDcxOSIsCiAgICAgICAgIm5hbWUiOiAiUGhhc2UgRmluYWwiCiAgICAgIH0sCiAgICAgICJjaGlsZF9yZWxhdGlvbnMiOiBbCiAgICAgICAgewogICAgICAgICAgImNhcmRzIjogWwogICAgICAgICAgICB7CiAgICAgICAgICAgICAgImlkIjogIjY0MDU4OTMiLAogICAgICAgICAgICAgICJjdXJyZW50X3BoYXNlIjogewogICAgICAgICAgICAgICAgImlkIjogIjMxNDc3MjgiLAogICAgICAgICAgICAgICAgIm5hbWUiOiAiQ29uY2x1w61kbyAyIgogICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgImNoaWxkX3JlbGF0aW9ucyI6IFsKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgInBpcGUiOiB7CiAgICAgICAgICAgICAgICAgICAgImlkIjogIjQ1ODEzOCIKICAgICAgICAgICAgICAgICAgfSwKICAgICAgICAgICAgICAgICAgIm5hbWUiOiAiUGlwZSAzIENvbmV4w6NvIiwKICAgICAgICAgICAgICAgICAgImNhcmRzIjogWwogICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICJpZCI6ICI2NDA3MDQ5IiwKICAgICAgICAgICAgICAgICAgICAgICJjdXJyZW50X3BoYXNlIjogewogICAgICAgICAgICAgICAgICAgICAgICAiaWQiOiAiMzE1MTE1MiIsCiAgICAgICAgICAgICAgICAgICAgICAgICJuYW1lIjogInBpcGUgMyBwaGFzZSAxIgogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgXQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIF0KICAgICAgICAgICAgfQogICAgICAgICAgXQogICAgICAgIH0KICAgICAgXQogICAgfQogIH0KfSc7Cgokbml2ZWwgPSAwOwokbml2ZWxNYXggPSAwOwokcG9zTGltID0gMDsKZm9yICgkaSA9IDA7ICRpIDwgc3RybGVuICgkanNvbik7ICRpKyspIHsKCSRjYXIgPSBzdWJzdHIoJGpzb24sICRpLCAxKTsKCWlmICgkY2FyID09ICd7JykgewoJCSRuaXZlbCsrOwoJCWlmICgkbml2ZWwgPiAkbml2ZWxNYXgpIHsKCQkJJG5pdmVsTWF4ID0gJG5pdmVsOwoJCQkkcG9zSW5pTml2ZWxNYXggPSAkaTsKCQl9Cgl9CglpZiAoJGNhciA9PSAnfScpIHsKCQlpZiAoJG5pdmVsID09ICRuaXZlbE1heCkKCQkJJHBvc0ZpbU5pdmVsTWF4ID0gJGk7CgkJJG5pdmVsLS07Cgl9CglpZiAoJGNhciA9PSAnLCcpIHsKCQkkcG9zTGltQW50ID0gJHBvc0xpbTsKCQkkcG9zTGltID0gJGk7Cgl9Cn07CmVjaG8gc3Vic3RyKCRqc29uLCAkcG9zTGltQW50KzEsICRwb3NGaW1OaXZlbE1heCAtICRwb3NMaW1BbnQgKyAxKSAuICc8YnI+Jzs=