Question: I currently have this code running. It is splitting the variable $json where there are },{ but it also removes these characters, but really I need the trailing and leading brackets for the json\_decode function to work. I have created a work around, but was wondering if there is a more elegant solution?

```
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5},{"a":1,"b":2,"c":3,"d":4,"e":5}';
$individuals = preg_split('/},{/',$json);

$loop_count =1;
foreach($individuals as $object){
    if($loop_count == 1){$object .='}';}
    else{$object ="{".$object;}
    print_r(json_decode($object));
    echo '<br />';
$loop_count++;
}
?>

```

EDIT:
The $json variable is actually retrieved as a json object. An proper example would be 

> 
> [{"id":"foo","row":1,"col":1,"height":4,"width":5},{"id":"bar","row":2,"col":3,"height":4,"width":5}]
> 
> 
>

Answer: 
As you (presumably) already know, the string you have to start with isn't valid json because of the comma and the two objects; it's basically two json strings with a comma between them.

You're trying to solve this by splitting them, but there's a much easier way to fix this:

The work-around is simply to turn the string into valid JSON by wrapping it in square brackets:

```
$json = '[' . $json . ']';

```

Voila. The string is now valid json, and will be parsed successfully with a single call to `json_decode()`.

Hope that helps.
You can always add them again.
Try this:

```
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5},{"a":1,"b":2,"c":3,"d":4,"e":5}';
$individuals = preg_split('/},{/',$json);

foreach($individuals as $key=>$val)
   $individuals[$key] = '{'.$val.'}';

```