Can not convert JSON to PHP Array: syntax error

Tried different online tools to convert Json to Php array. Unfortunately, I alwas get error: Suntax Error. What's wrong with this:

"content":{
"txt":" ",
"ent":[
{
"tp":"IM",
"data":{"mime":"image/jpeg",
"val":"image_content",
"width":324,
"height":283,
"name":"filename.jpg",
"size":44596}
}],
"fmt":[
{"len":1}
]}

1 answer

  • answered 2021-04-21 12:46 Mathieu27

    You are missing the two braces at the beginning and end of your json. You can use json_decode :

    <?php
    
    $str = 
        '{
            "content":{
            "txt":" ",
            "ent":[
            {
            "tp":"IM",
            "data":{"mime":"image/jpeg",
            "val":"image_content",
            "width":324,
            "height":283,
            "name":"filename.jpg",
            "size":44596}
            }],
            "fmt":[
            {"len":1}
            ]}
        }';
        
          
        $response = json_decode($str, TRUE);
        print_r($response);
    
    ?>