Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBuilder json keys with @ symbol to use schema.org metadata using json-ld

In my jbuilder template I'm not able to have keys starting with "@" symbol. e.g. "@context". What should I do.

I need keys like this for json-ld metadata in my application.

I want to get json like below

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

{
    "@context": "http://schema.org",
    "@type": "Article",
    "publisher": "The Ghost Blog",
    "author": {
        "@type": "Person",
        "name": "John O'Nolan",
        "image": "http://blog.ghost.org/content/images/2013/Nov/gravatar_j7_200.jpg",
        "url": "http://blog.ghost.org/author/john",
        "sameAs": "http://twitter.com/JohnONolan"
    },
    "headline": "11 Tools We Use at Ghost for Distributed Teams &amp; Digital Nomads",
    "url": "http://blog.ghost.org/distributed-team-tools/",
    "datePublished": "2014-12-15T14:09:18.000Z",
    "dateModified": "2014-12-18T22:13:49.000Z",
    "image": "http://blog.ghost.org/content/images/2014/12/ghostdistrib.jpg",
    "keywords": "Remote Work",
    "description": "Doing remote work is tough. The freedom is great, but distributed team tools and communication are essential to making it work. Here are our top apps...."
}
    </script>
like image 937
lightsaber Avatar asked Jan 02 '15 05:01

lightsaber


1 Answers

Solved it. It was pretty simple.

json.set! "@context", "http://schema.org"
like image 125
lightsaber Avatar answered Sep 24 '22 06:09

lightsaber