0

I am trying to call my local json file for the below code but it's not getting. please help.
How to call local json file in the place of below statement " const { data } = await axios('https://jsonplaceholder.typicode.com/posts')" .

Could please help me with this. And also please check the below code for your reference. I am using the react-bootstrap table.

1 Answer 1

1

import the json file first

import jsondata from ‘./path/data.json’;

then parse and load it.

const data  = JSON.parse(JSON.stringify(jsondata));
Sign up to request clarification or add additional context in comments.

4 Comments

I used like this belowbut its not working. import invoicedate from '../pdf/inoivelist.json' useEffect( () => { const fetchInvoicelists = async () => { // const { data } = await axios(invoicedate) const data = JSON.parse(invoicedate) setPosts({ blogs: data }) console.log(data) } fetchInvoicelists() }, [setPosts])
please help with this
getting this error VM7909:1 Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1 at JSON.parse (<anonymous>)
Stringify the Json then parse it, edited the answer please check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.