I have a file with content similar to this:
[{"color":1,"blocks":[[{"id":64}]]},{"color":1,"blocks":[[{"id":64},{"id":64}],[{"id":1}]]},{"color":2,"blocks":[[{"id":64},{"id":64}],[{"id":1}]]}]
For example the file above has 3 objects with elements: color and blocks.
I am searching for an easy way with PHP to output only one object of the file. (remove outer []-brackets and split first level {}-brackets into different elements of an array or different strings or something)
The result should be for object1
{"color":1,"blocks":[[{"id":64}]]}
or for object2
{"color":1,"blocks":[[{"id":64},{"id":64}],[{"id":1}]]}
How to say PHP take the string and split it for each {"color" it can find into parts or by using the first level {}-brackets?
at the moment I am using $config=json_decode($file,true); and my code is like
echo '{"color":'.$config[2]["color"].'"blocks" ... but thats crazy the object has too many elements
i need a way like echo $config[2] that outputs {"color":2,"blocks":[[{"id":64},{"id":64}],[{"id":1}]]}
I tried to read the file as string and use explode but "}," or "color" as delimiter does not work and I can't find a valid delimiter.