I’m stuck on what I assume is a newbie problem. I want to insert JSON-LD into my header, and the json is in files in my ./data/section/whatever.json files. What I’ve done is this:
<script type="application/ld+json">
{{ readFile (printf "./data/%s/%s.json" .Section (path.Base .RelPermalink)) }}
</script>
Snag is, what’s output is this:
<script type="application/ld+json">
"{\n\t\"@context\": \"https://schema.org\",\n\t\"@type\": \"BarOrPub\",\n\t\"address\": {\n\t\t\"@type\": \"PostalAddress\",\n\t\t\"addressCountry\": \"ZA\",\n\t\t\"addressLocality\": \"Parkview\",\n\t\t\"addressRegion\": \"Johannesburg\",\n\t\t\"postalCode\": \"2132\",\n\t\t\"streetAddress\": \"Princess of Wales Terrace\"\n\t},\n\t\"geo\": {\n\t\t\"@type\": \"GeoCoordinates\",\n\t\t\"latitude\": \"-26.1622097\",\n\t\t\"longitude\": \"28.0304166\"\n\t},\n\t\"hasMap\": {\n\t\t\"@type\": \"Map\",\n\t\t\"url\": \"https://www.google.co.za/maps/place/Zoo+Lake+Bowls+Club/@-26.1622097,28.0304166,17z/data=!3m1!4b1!4m5!3m4!1s0x1e950c637be96a97:0x647573ab4607e2cc!8m2!3d-26.1622076!4d28.0330357\"\n\t},\n\t\"name\": \"Zoo Lake Bowls Club\",\n\t\"telephone\": \"0114860843\",\n\t\"url\": \"http://www.zoolakebowls.co.za/\"\n}\n"
</script>
Before diving into trying to fix this with replaceRE (I hardly ever use regular expressions, and my heart sinks every time I have to), I wondered if there’s some built in trick?
I’ve tried this
<script type="application/ld+json">
{{ jsonify (index .Site.Data .Page.Section) }}
</script>
But again it produces raw text instead of JSON.