json_decode remove null,false,true from array

I have a json result below.

$abc =  '{
    "id":"375",
    "name":"Nilesh Y",
    "email":"nilesh.yadav@test.co.in",
    "mobile":"9076330330",
    "tracking_number":null,
    "home_tagged_address_id":null,
    "office_tagged_address_id":null,
    "time":1427254525,
    "logged_in":true,
    "method":true,
    "error":null,
    "home_address":null,
    "office_address":null
 }';


$a = json_decode($abc,true,JSON_BIGINT_AS_STRING);

print_r($a);

after json_decode decode the result is .

Read More
Array ( [id] => 375 [name] => Nilesh Y [email] => nilesh.yadav@intelliswift.co.in [mobile] => 9076330330 [tracking_number] => [home_tagged_address_id] => [office_tagged_address_id] => [time] => 1427254525 [logged_in] => 1 [method] => 1 [error] => [home_address] => [office_address] => )

If u see the result it removed the error : null and home_address : null

means [home_address] => "" is blank
I want to print that null value in array kindly let me know how to do that

Related posts

Leave a Reply

3 comments

  1. Use var_dump instead of print_r. Install the xdebug extension which will make var_dump’s output even nicer.

    Do you see? ( http://3v4l.org/Y58fC ) var_dump() will output the following:

    array(13) {
      'id' =>
      string(3) "375"
      'name' =>
      string(8) "Nilesh Y"
      'email' =>
      string(23) "nilesh.yadav@test.co.in"
      'mobile' =>
      string(10) "9076330330"
      'tracking_number' =>
      NULL
      'home_tagged_address_id' =>
      NULL
      'office_tagged_address_id' =>
      NULL
      'time' =>
      int(1427254525)
      'logged_in' =>
      bool(true)
      'method' =>
      bool(true)
      'error' =>
      NULL
      'home_address' =>
      NULL
      'office_address' =>
      NULL
    }
    

    You see, json_decode() is working as expected you simply couldn’t see it since print_r will print nothing for a NULL.

  2. you have received your intended result itself.
    When you do print_r, null value are not displayed.
    The proof itself is that key exists while value doesn’t.
    you can confirm using var_dump