Could you suggest the beter way to convert this json structure to a PHP array?

Hi Experts!

Could you suggest the beter way to convert this json structure to a PHP array?

Sample: 
{
  "numeroGuia": "sample string 1",
  "paciente": {
    "nome": "sample string 1",
    "endereco": {
      "cep": "sample string 1",
      "logradouro": "sample string 2",
      "numero": 3,
      "complemento": "sample string 4",
      "bairro": "sample string 5",
      "cidade": "sample string 6"
    },
    "dataNascimento": "2018-10-22T17:53:58.4603585-03:00",
    "cpf": "sample string 2",
    "telefone": "sample string 3",
    "email": "sample string 4",
    "sexo": "sample string 5",
    "peso": 1.1,
    "convenio": 1,
    "plano": "sample string 6",
    "matricula": "sample string 7"
  },
  "contratante": {
    "tipo": 64,
    "contrato": 1
  },
  "atendimento": {
    "diagnostico": "sample string 1",
    "recurso": "sample string 2",
    "exames": "sample string 3",
    "carater": 64,
    "motivoAtendimento": "sample string 4",
    "cid": "sample string 5",
    "produto": "sample string 6"
  },
  "captacao": {
    "cor": "sample string 1",
    "dataInicio": "2018-10-22T17:53:58.4759589-03:00",
    "dataFim": "2018-10-22T17:53:58.4759589-03:00"
  },
  "origem": {
    "dataAgendadaChegadaOrigem": "2018-10-22T17:53:58.4759589-03:00",
    "nomeLocal": "sample string 1",
    "endereco": {
      "cep": "sample string 1",
      "logradouro": "sample string 2",
      "numero": 3,
      "complemento": "sample string 4",
      "bairro": "sample string 5",
      "cidade": "sample string 6"
    },
    "telefone": "sample string 2",
    "responsavel": "sample string 3"
  },
  "destino": {
    "dataAgendadaChegadaDestino": "2018-10-22T17:53:58.4759589-03:00",
    "nomeLocal": "sample string 1",
    "endereco": {
      "cep": "sample string 1",
      "logradouro": "sample string 2",
      "numero": 3,
      "complemento": "sample string 4",
      "bairro": "sample string 5",
      "cidade": "sample string 6"
    },
    "telefone": "sample string 2",
    "responsavel": "sample string 3"
  }
}

Open in new window


Thanks in advance!
Eduardo FuerteDeveloper and AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Unsure exactly what you're asking.

Expand your question to clarify the exact, current problem you're having with your current JSON structure.

You have many nested structures, so likely best to keep this JSON, rather than trying to flatten your data into a simple array.
Julian HansenCommented:
I don't understand the question - better how?

You can convert from JSON to a PHP structure with json_decode()

$data = json_decode($json);
// WHERE $json HOLDS THE JSON string

Open in new window


After that you would access it as you would any object / array combination

echo $data->paciente->endereco->complemento;

Open in new window

Will output
sample string 4

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eduardo FuerteDeveloper and AnalystAuthor Commented:
Hi Julian

better how?

Maybe it's the only way available...

Thanks for help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.