oompahloompah
oompahloompah

Reputation: 9333

PHP fails to parse this JSON string - what's wrong?

<?php
$b = '{
    "encoding" : "UTF-8",    
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],
    "indent" : { "length" : 3, "use_space" = true }
}';

print "\n\n\n=================================\n";
$barr = json_decode($b, true);
print_r($barr);

?>

This prints nothing on the console. Is tehre something wrong with the JSON format above? - or am I missing a trick?

Upvotes: 1

Views: 422

Answers (3)

xkeshav
xkeshav

Reputation: 54016

$b = '{
    "encoding" : "UTF-8",    
    "plug-ins" : [
        "python",
        "c++",
        "ruby"
        ],
    "indent" : { "length" : 3, "use_space" : true }
}';

print "\n\n\n=================================\n";
$barr = json_decode($b, true);
print_r($barr);

?>

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382616

That is because your JSON isn't valid. Check out here.

This:

"use_space" = true 

Must be:

"use_space" : true 

Upvotes: 4

BoltClock
BoltClock

Reputation: 723388

The indent property has an error in its use_space property:

"indent" : { "length" : 3, "use_space" = true }

The equal should be a colon.

"indent" : { "length" : 3, "use_space" : true }

Upvotes: 3

Related Questions