I am importing data from json like this
import data from './data.json'
where data.json looks somewhat similar to this
{
"data": [
{"title": "Some title", "text": "Some text"},
{"title": "Some title", "text": "Some text"},
{"title": "Some title", "text": "Some text"}
]
}
so to use it in my file I'd usually do something like data.data[0].title
which in my opinion is not the cleanest way, ideally I'd like to use it like data[0].title
is there a way I can include or edit my json file to acheive this?
You can import {data} from './data.json
. That will only import that data
key from the object, and place it into a variable called data
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With