Convert JSON data structure to Object

Asked

Viewed 55 times

0

I’m using the framework Materializecss - autocomplete, and would like to feed a autocomplete field with data coming from my base. The 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 valid JSON structure into the structure used by the autocomplete?

But if someone knows how to make the autocomplete work with that valid JSON, even better.

I’m using php, jquery and mysql

Thanks for your cooperation.

1 answer

0

Solved!

People managed 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
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.