Json cleaning includes use

I am importing data from json like this

import data from './data.json' 

where data.json looks a bit like this

 { "data": [ {"title": "Some title", "text": "Some text"}, {"title": "Some title", "text": "Some text"}, {"title": "Some title", "text": "Some text"} ] } 

therefore, to use it in my file, I usually did something like data.data[0].title , which, in my opinion, is not the cleanest way, ideally I would like to use it as data[0].title , is there a way that I can include or edit my json file to achieve this?

+5
source share
1 answer

You can import {data} from './data.json . This will import only this data key from the object and put it in a variable called data .

+5
source

All Articles