Export Dataframe from python / pandas to javascript

I am trying to export data from python to javascript.

I have a python pandas dataframe df that I export to a file “formatted.json” using the following code

with open('../data/formatted.json', 'w') as outfile:
    df.to_json(outfile)

Here’s an excerpt of the ../data/formatted.json file:

{"game_id":{"0":"bda33adca828c09dc3cac3a856aef176","1":"03f67404824aee9be3cba7bc3a2a3499","2":"658843f757b400ecbc5587e8ed3e5521","3":"51e4e3d8fe4d2ecf7f926b5049696f0e","4":"d2f82f3973ced311faac8c6bd90b16b9","5":"c1e42fa78b9a527487211c2dfccad8fb","6":"ee25ac1aa64a6b33cfd7d42881e4f7b9"}}

I then try to import this data in javascript to read into my react component using

import oddsdata from '../data/formatted.json'

//returns error
Module not found: Can't resolve '../data/formatted.json'

I think the problem is because i dont have an export in my formatted.json file? How can I configure either the python export or the js import to overcome this issue?

the js file is saved in src/betting/betinterface/betinterface.js and the data is saved in src/data/formatted.json

Answer

The link to the data file formatted.json is not correct as per our discussion in the comment.

You should change it to

import oddsdata from '../../data/formatted.json'