I have a problem with a piece of JSON and PHP\'s json_decode()
.
We receive JSON from a customer\'s publishing solution, and although it validates, json_decod
You will not get that to work. json_decode exports the data as php objects or arrays - and therefore no duplicate keys / properties are allowed.
Maybe you can convince the customer to change the json format into something like this:
{
"articles":{
"article":{
"title":"This is the title",
"document":{
"text_article":[
{
"type":"p",
"content":[
"- The first sentence."
]
},
{
"type":"h3",
"content":[
"The first subtitle."
]
},
{
"type":"p",
"content":[
"- One sentence.",
"Another sentence.",
"- A quote."
]
}
]
},
"knr":"0001"
}
}
}
There, you have an array text_article
containing objects for each tag - each containing an array of contents. The objects can be extended by further attributes as needed.
just to add a possible option...
the library jsonlint can be used to validate your json string. It will take arguments to either ignore/detect duplicate keys.
whilst this wont fix your problem, at least youd be able to detect any errors so avoiding data corruption.