JSON-LD tag on Phoenix Liveview

Hello!

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?

Today I was working with a json_ld map that looks like:

%{
  "@context" => "https://schema.org",
  "@type" => "Restaurant",
  "address" => %{
    "@type" => "PostalAddress",
    "addressCountry" => "IE",
# ..... etc

and I get it in my HTML like this (in root.html.heex):

    <%= if !!assigns[:current_json_ld] do %>
      <script type="application/ld+json">
        <%= @current_json_ld |> Jason.encode!(escape: :html_safe, pretty: true, maps: :strict) |> raw() %>
      </script>
    <% end %>

sorry for the necro but not much else found when I search the forum for type="application/ld+json". This info would have saved me some time today.