<p>If you are using something like this to get your entry:</p>

<pre><code>{% set entry = craft.entries.section('blog').limit(1).id('21') %}
</code></pre>

<p>then Craft is actually returning an ElementCriteriaModel object, even if it is only one entry.</p>

<p>To ensure that the <code>entry</code> variable only contains a single entry, you need to call the <code>first()</code> method like this:</p>

<pre><code>{% set entry = craft.entries.section('blog').limit(1).id('21').first() %}
</code></pre>

<p>More details in the docs here: <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow">https://craftcms.com/docs/templating/elementcriteriamodel</a></p>

CC BY-SA 3.0
2015-12-04T15:35:42.247Z
2015-12-04T15:35:42.247Z
Steve Rowling
<p>Inside a JSON template I find an entry using <code>id</code>, the result title can't be seen using <code>entry.title</code> but I can see it with <code>entry[0].title</code>. There is another step or encoding I have to use? </p>

<templating><entry><json>
Fail in JSON using Twig
# Fail in JSON using Twig

(Asked by: username_0 on 2015-12-04)

Inside a JSON template I find an entry using `id`, the result title can't be seen using `entry.title` but I can see it with `entry[0].title`. There is another step or encoding I have to use?

**Tags:** templating, entry, json

---

## 1 answers

### Answer by username_1 on 2015-12-04. Score: 1 | Accepted answer

If you are using something like this to get your entry:
{% set entry = craft.entries.section('blog').limit(1).id('21') %}

then Craft is actually returning an ElementCriteriaModel object, even if it is only one entry.
To ensure that the entry variable only contains a single entry, you need to call the first() method like this:
{% set entry = craft.entries.section('blog').limit(1).id('21').first() %}

More details in the docs here: https://craftcms.com/docs/templating/elementcriteriamodel


---

