Send JSON over HTTP in Processing

Hey! Looking for tutorials on how to use HTTP to send images and/or data in JSON-format. Locally/localhost is fine, not over the internet. All hints much appreciated :slight_smile:

sorry, looks like second time
that your question is not easy understood / to answer??

-a- do you want have 2 computer in your local net work
-b- both running processing
-c- and they should exchange strings
-d- and the string content you want make JSON record style.

so for -a- -b- -c-
could try

  • SharedCanvasServer
  • SharedCanvasClient

there erase the data part and line drawing
and just send and println() || text() a string

now can design the string content to JSON record
just instead save to file send to server/client.

Sorry if my question was not clear.

I want one computer to run Processing + another software (Runway, which is still in Beta) and I want to send information via HTTP from Processing to Runway in JSON format. Runway already listens for the information on a specific port.

What I need is therefor an example of how to make Processing send via HTTP from Processing in JSON format.

? you have the examples from that group already running?
posenet / OSC / JSON

ok, fits more to your last question

I know, my question here is about HTTP, not OSC - which I got working :slight_smile:

A web server is request-based. The easiest thing is to run a web server – any web server, like WAMP or MAMP or nginx or SimpleHTTPServer etc. – on Machine 1. Sketch 1 writes a JSON file into the web server directory. On Machine 2, Sketch 2 loads the file from a URL with either loadJSONObject or loadJSONArray – both take http URLs as arguments.

If you need to do something more complicated in the way that you query from Sketch 2 then you can use the HTTP-Requests library, but it shouldn’t be necessary:

Use Base64 encoding to save your binary jpeg / gif / zip file / database / Doom level file / etc. into a JSON field as a string.

You can encode and decode with java.util.Base64, like this:

import java.util.Base64;
byte[] encodedBytes = Base64.getEncoder().encode("Test".getBytes());
System.out.println("encodedBytes " + new String(encodedBytes));
import java.util.Base64;
byte[] decodedBytes = Base64.getDecoder().decode(encodedBytes);
System.out.println("decodedBytes " + new String(decodedBytes));

See related past discussion:

Of course, if you are already using http, then this might be kind of silly. You can just write the image into the web server path and load it by URL. If you need to send a list of images, write their URLs into the JSON file – rather than base64-encoding them – and then you can retrieve them by url string after your read the JSON file.