javascriptfileprocessingp5.js

P5Js modifying local file such as json or xml or table


P5Js allows you write a json/table/xml file on the disk but I couldn't find a way to modify the existing file.

There is way through which you can open a local file[json/table/xml] in P5js and there is another way thought which you can write/create a file on local disk but I couldn't found how to modify a local file or add a new entry in the existing local json or table or xml file.

  1. P5.Js
  2. P5.Js write a file
  3. P5.Js loadFile
  4. P5.Js Table reference

I do found some example to this but they are using different technologies Link


Solution

  • You can.

    If you want to use the browser, you have two options:

    1. Use saveTable(), saveJSON(), etc. which will download a file. (Press the edit button in the reference snippet, hit run see what I mean)
    2. Try localstorage for small pieces or data, or use a database otherwise (may require a wee bit of server-side scripting)

    With option 1 you'd have a loop like this:

    1. load the file (file browse dialog or drop the file onto the browser (there's a p5.js example for that))
    2. parse and modify the file in p5.js
    3. save/download the file from p5.js

    Other options may include using a wrapper for your js code into an application. As you've mentioned, app.js/electron.js/cordova/etc. will provide options.

    It might be worth trying node.js since there already is a p5.js node.js tutorial out there