-1

For a project, I need to read this type of object but it is impossible for me to find which type it is. Any idea ?

{"variation"=>[{"accommodationType"=>"test" }]}

First I thought of JSON but we don't use => in JSON, and after i need to read this object with PHP.

T.J. Crowder
  • 879,024
  • 165
  • 1,615
  • 1,639
Julien Martin
  • 121
  • 1
  • 1
  • 6

1 Answers1

1

As suggested in the comments, the => can be replaced by : and then json_encode() can be used.

$input = '{"variation"=>[{"accommodationType"=>"test" }]}';
$obj = json_decode(str_replace('=>',':',$input));

var_export($obj);

Result:

(object) array(
   'variation' => 
  array (
    0 => 
    (object) array(
       'accommodationType' => 'test',
    ),
  ),
) 
jspit
  • 3,933
  • 1
  • 6
  • 13