1

I was trying to debug some error, and then I realized that json_decode doesn't work as intended and removes the boolean values.

print_r(json_decode('{
"items": {
    "DarkEnergy": {
        "quantity": "1",
        "hidden": false
    },
    "Opium": {
        "quantity": "1",
        "hidden": false
    }
},
"set": {
    "item": {
        "quantity": "1",
        "hidden": false,
        "items": {
            "0": {
                "name": "dragon",
                "quantity": "1"
            }
        }
    }
}
}'));

stdClass Object ( [items] => stdClass Object ( [DarkEnergy] => stdClass Object ( [quantity] => 1 [hidden] => ) [Opium] => stdClass Object ( [quantity] => 1 [hidden] => ) ) [set] => stdClass Object ( [item] => stdClass Object ( [quantity] => 1 [hidden] => [items] => stdClass Object ( [0] => stdClass Object ( [name] => dragon [quantity] => 1 ) ) ) ) ) 

What's going on?

aLex
  • 1
  • 11

1 Answers1

3

The value false is still there. Its just print_r which does not deal with displaying booleans nicely. (for giggles, the same thing happens if you try to echo a boolean).

If you use var_dump() you will see the boolean is still in the array.

Erik Baars
  • 2,278
  • 1
  • 8
  • 14