I am using json_encode to convert the array to json. But json is giving braces {} if value is blank for some key . I want the value should come null or "" blank. Please help .Below is the code :
<?php
$postData='<Lead>
<General>
<dealer></dealer></General> </Lead>';
$array_data = json_encode(simplexml_load_string($postData));
$array_data=json_decode($array_data) ;
$dealer=$array_data->General->dealer;
$data=array('dealer'=>$dealer);
echo $objectJson =json_encode($data);
?>
response is : {"dealer":{}}
simplexml_load_stringgenerates empty objects sojson_encode()correctly encodes them to{}: eval.in/710579