Json with livewire

hi

how i pass json to livewire component

i do iike this:

in livewire component:

public $navigation = “{
name:‘waze,
english_name:‘navigation’,
icon:‘fab fa-waze’,
text:’’,
link:‘waze://?q=’,
}”;

in blada:

{{$navigation->name}}

but i get error
"
ErrorException
Trying to get property ‘name’ of non-object (View:

"

Hey @haiibooo,

you are simply passing a String into the variable and therefore the view, but you try to access data like you would with an PHP object.

You could use json_decode to convert the string, but since it‘s not properly encoded this also won‘t work.

May i ask why you want to put json in there in the first place?

i found how to do that

need to leran more :slight_smile:

you can use json_encode in you component like this

// ....
public $naviagation;

public function mount()
{
  $this->navigation = json_encode([
      'name' => 'waze',
      'englishName' => 'navigation',
      'icon' => 'fab fa-waze',
      'text' => [
        'link' => 'foobar',
     ],
  ], true);
}

my advice to you is to do more effort and learn some PHP basics before playing with Laravel or livewire

Find More here

Best of Luck.