How do I query a JSON array for a single element in Nuxt 3 and Nuxt Content?
├── @nuxt/content@2.3.0
└── nuxt@3.0.0
content/people.json
[
{
"name": "Name1",
"id": 1
},
{
"name": "Name2",
"id": 2
}
]
Querying all of the people data results in this:
[
{
"_path": "/people",
"_dir": "",
"_draft": false,
"_partial": false,
"_locale": "en",
"body": [
{
"name": "Name1",
"id": 1
},
{
"name": "Name2",
"id": 2
}
],
"_id": "content:people.json",
"_type": "json",
"title": "People",
"_source": "content",
"_file": "people.json",
"_extension": "json"
}
]
pages/people/[id].vue
<template>
<pre>{{ data }}</pre>
</template>
<script setup>
const route = useRoute();
const id = route.params.id;
const data = await queryContent("people")
.where({ id }) // **What should this be? I can't seem to get any variants to work**
.findOne();
</script>
I can query the full array of people okay on the index page. However, I would like to now get the single "person" out of the JSON array on the [id].vue
page, but I'm not sure how to query this document with a where
clause in Nuxt Content.