Parsing JSON data in Processing

Hi,

In this Processing documentation, a JSON file can be loaded with this line of code:

json = loadJSONObject("data.json");

I would like to do the same, but from a serial input from an Arduino. I tried this:

val = myPort.readString(); 
  
  if (val != null) {
    data = loadJSONObject(val);
}

However, I get the error:

The file is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

Is there a way to read and parse serial JSON data?

possibly you have end of line characters in the String
try

val = myPort.readStringUntil('\n')

readStringUntil() will read the string until '\n' is found and discards it

Hi,

Thank you for your response, however that didn't work.

with readString() try setting the Serial monitor input to "No Line Ending"

Hi,

Thanks. How would I go about that?

Personally I would ask the question on the Processing forum: https://discourse.processing.org/.

There are a few people here that have worked with Processing but not many.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.