Search code examples
pythonjsonprocessingosc

How to decode a json.dumps from python in Processing?


I have a python OSCclient that sends a json.dumps(dictionary) to a OSCP5 server in Processing (Java Mode).

python side:

'input_dict = {'text': 'Dies ist der erste Kommentar', 'cat': 'insinuation',   'category_counter': {'praise': 0, 'insinuation': 1, 'dissence': 0, 'lecture': 0, 'concession': 0}, 'is_locked': False}
data = json.dumps(input_dict)
client.send_message('/display_input', data)        

The message is being sent and received, but there seems to be a problem with decoding the json data in the function oscEvent. Processing Side:

void oscEvent(OscMessage m) {
  print("### received an osc message.");
  print(" addrpattern: "+m.addrPattern());
  println(" typetag: "+m.typetag());
  if (m.checkAddrPattern("/display_input") == true) {
      println("INCOMING :", m.arguments()[0]);
      JSONObject new_utt = loadJSONObject((String) m.arguments()[0]);

processing prints out:

received an osc message. addrpattern: /display_input typetag: s

INCOMING : {"text": "Dies ist der erste Kommentar", "cat": "dissence", "category_counter": {"praise": 0, "insinuation": 0, "dissence": 1, "lecture": 0, "concession": 0}, "is_locked": false}

The file "{"text": "Dies ist der erste Kommentar", "cat": "dissence", "category_counter": {"praise": 0, "insinuation": 0, "dissence": 1, "lecture": 0, "concession": 0}, "is_locked": false}" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

my question: is there a way to send jso.dumps via OSC to Processing where I can open them as JSONObjects?


Solution

  • According to the documentation, loadJSONObject interprets its argument as a file name that points to a JSON file.

    To parse JSON from a string, use the function parseJSONObject instead.