GodziLaravel's avatar

Json_encode without quots

how to prevent the quotes when I want to print my variable as json between tags

<script type="application/ld+json">
--- here ---
</script>

because now , from the view when I :

   {{  json_encode($data["application_id_json"])  }}

it returns me inside the html code somethings with quotes and I want it as a simple json code

{&quot;@context&quot;:&quot;http:\/\/schema.org&quot;,&quot;@type&quot;:&quot;Product&quot;,&quot;sku&quot;:&quot;ypxfBlbC&quot;,&quot;name&quot;:&quot;Mouse Immunoglobulin E (IgE) ELISA Kit&quot;,&quot;productID&quot;:&quot;abx573478&quot;,&quot;category&quot;:&quot;lab\/elisas\/mouse&quot;,&quot;description&quot;:&quot;Principl&quot;,&quot;url&quot;:&quot;http:\/\/&quot;,&quot;brand&quot;:{&quot;@type&quot;:&quot;Brand&quot;,&quot;name&quot;:&quot;abbex&quot;,&quot;logo&quot;:&quot;url&quot;},&quot;offers&quot;:{&quot;@type&quot;:&quot;Offer&quot;,&quot;price&quot;:&quot;851&quot;,&quot;availability&quot;:&quot;http:\/\/schema.org\/InStock&quot;,&quot;priceCurrency&quot;:&quot;eur&quot;}}

instead of :

{"@context":"http:\/\/schema.org","@type":"Product","sku":"ypxfBlbC","name":"Mouse Immunoglobulin E (IgE) ELISA Kit","productID":"abx573478","category":"lab\/elisas\/mouse","description":"Principl","url":"http:\/\/","brand":{"@type":"Brand","name":"abbex","logo":"url"},"offers":{"@type":"Offer","price":"851","availability":"http:\/\/schema.org\/InStock","priceCurrency":"eur"}}
0 likes
1 reply
Cronix's avatar
Cronix
Best Answer
Level 67

Try using {!! !!} instead of {{ }}. Anything run through {{ }} gets escaped using htmlspecialchars(), while {!! !!} does not.

https://laravel.com/docs/5.5/blade#displaying-data

But, you'd probably want to not use blade at all for outputting json. You'd just do what they show in the user guide:

<script>
    var app = <?php echo json_encode($array); ?>;
</script>
1 like

Please or to participate in this conversation.