Skip to main content
Known Participant
December 22, 2021
Answered

read json file in the desktop using jquery

  • December 22, 2021
  • 1 reply
  • 3475 views

Hi All,

Im working in CEP panel, my requirement is to read json file in the desktop and insert the data into html fields.

 

I can't able to read the json file in the local path using jquery. And also I tried to integrate the JS code in Jquery that also not works.

Is there any option to fetch the data in the local path using jquery. Any help is much appreciated.

Thanks

This topic has been closed for replies.
Correct answer Charu Rajput

Sure I will send! Thanks


I have seen your code. There are two issues

1. JSON file data

2. Use complete path to the file in the _filePath variable

 

I hope it will work after doing these changes.

1 reply

Charu Rajput
Community Expert
December 22, 2021

Hi,

In CEP panels you can use node module 'fs' to read the file. Below is the simple example to read json file in CEP panel.

 

var filePath = '/Users/charu/Desktop/test.json'
_jsonData = cep.fs.readFile(filePath)
if (_jsonData.err == 0) {
    var _data = JSON.parse(_jsonData.data)
}

 

 

NOTE: Change filePath value as per your requirements.

Best regards
Rocky@Author
Known Participant
December 23, 2021

Thanks Charu! 

This Code was not work at my end. If I need to include any library js file for this code works?

 

Charu Rajput
Community Expert
December 23, 2021

There is no need to include anything. These nodes modules are in built. When you say it is not working, could you please explain what exactly not working or what error are you getting? You just need to enable the node parameter in manifest file.

Best regards