I need to put some JSON-LD content inside a script tag. Today, I’m put the content like this:
page_live.ex
defmodule ProjectWeb.PageLive do
use ProjectWeb, :live_view
@data_structure %{
"@context": "http://www.schema.org",
"@type": "WebSite",
name: "Project",
url: "https://project.com/"
}
@impl true
def mount(_params, _session, socket) do
socket = assign(socket, data_structure: @data_structure)
{:ok, socket}
end
end
root.html.leex
<!DOCTYPE html>
<html lang="pt-BR">
<head>
...
<%= if @data_structure do %>
<script type='application/ld+json'>
<%= Poison.encode!(@data_structure) %>
</script>
<% end %>
...
</head>
<body>
<%= @inner_content %>
</body>
<html>
The Poison lib always convert to String. I need a JSON.
How can I put the JSON content inside the script tag?