0

i am trying to create the json code below using php but putting curly braces in an array produces an error:

Parse error: syntax error, unexpected '{' in >/opt/lampp/htdocs/bulksms.php on line 23

 {

"properties": {
        "delivery_mode": 1,
        "headers": {}
    },

"headers": {},
"props": {},

}

Is there a way i can escape these characters (the curly braces) without putting them in a string. Below is the php code that i have so far.

$jsonData = array(
      'properties' =>  array(
          'delivery_mode' => 1,
          'headers' => {}
        ),

      'headers' => {},
      'props' => {},
    );
tendaitakas
  • 328
  • 5
  • 18

1 Answers1

2

PHP code demo

$jsonData = array(
      'properties' =>  array(
          'delivery_mode' => 1,
          'headers' => (object) array()
        ),

      'headers' => (object) array(),
      'props' => (object) array(),
    );
print_r(json_encode($jsonData));

Output:

{
    "properties": {
        "delivery_mode": 1,
        "headers": {}
    },
    "headers": {},
    "props": {}
}
Sahil Gulati
  • 15,028
  • 4
  • 24
  • 42