Convert data structure in JSON to Object

0

I'm using the framework Materializecss - autocomplete , and would like to feed an autocomplete field with data coming from my database. Autocomplete works with data in the following object structure:

{
  "Apple": null,
  "Microsoft": null,
  "Google": 'https://placehold.it/250x250'
}

And my data is exported in the valid JSON structure below (the data is dynamic):

[{
 "Apple": null
 },
 {
 "Microsoft": null
 },
 {
 "Google": 'https://placehold.it/250x250'
}]

So, how do I convert this my valid JSON structure into the structure used by autocomplete?

But if someone knows how to make autocomplete work with this valid JSON, better yet.

I'm using php, jquery and mysql

I thank you for your cooperation.

    
asked by anonymous 01.12.2017 / 14:14

1 answer

0

Solved!

I was able to export my JSON structure into a simple JSON structure.

$list = $stm->fetchAll(PDO::FETCH_OBJ);

foreach ($list as $key => $value) {
   $data[$value->nome]  = null;    
} 

return json_encode($data,  true);

Exported exactly the following structure:

{
 "Apple": null,
 "Microsoft": null,
 "Google": null
}
    
02.12.2017 / 16:06