Consuming and/or creating JSON data in Workflow 8.5?

I’m hoping to figure out a way to have Workflow interact with JSON files. I understand that Designer can, but I need to be able to manipulate JSON files outside of Designer.

This post mentions having Designer work with JSON from “A PlanetPress Workflow process that returns JSON data” so I’m hoping it’s in there somewhere.

The main use case is needing to post JSON data via a REST API through Workflow.

Thanks!

So I just ran across this how to article that does answer my question for the most part…

Communicate with HTTP API

It would appear that the way to build and parse JSON is via the Workflow Run Script task using Javascript as the language.

A word of feedback about the organization of the how to articles… I can’t find any way to search through them!

If I’m looking to find info on doing something specific (say looking for all articles mentioning ‘JSON’) ____ I have to manually browse all the articles! Please consider implementing some type of search capability. I do see ‘tags’ but in this case tags wouldn’t have helped as the article I needed was not marked with the JSON tag. Full text article search would be much better.

If anyone has additional information to add on working with JSON in workflow I’d love to hear it.

Thanks!

Nate

Hello Nate,

Thanks for your feedback.

There are several ways to work with JSON data from within Workflow. Below a few techniques I use on a regular basis:

  1. Create File plugin to construct and return JSON
  2. OpenScript plugin to construct JSON and return via the Create File plugin

Construct JSON and return via the Create File plugin
Use the Create File plugin to construct a JSON string and return this at the end of your process. The process starts with an HTTP Server Input of which it’s MIME type is set to “application/json”.

Sample Create File step contents showing a JSON string using information, a local variable and JobInfo1:

{
"status":"error",
"message":"%{error_message}",
"id","%1" 
}

The simplified process looks like this:

OpenScript plugin to construct JSON
The OpenScript plugin supports various scripting languages including JavaScript. You can use JavaScript to construct your JSON object. This makes it is easier to conditionally add information/properties as you can use statements in your code (if, switch).

The following code creates a JSON object and stores it in a JobInfo. Subsequently a Create File step is used to return the JSON string as described in the first example:

var myObj = {};
myObj.status = "OK";
myObj.id = Watch.GetJobInfo(1);
myObj.foobar =  Watch.GetVariable("foobar");

Watch.SetJobInfo(2, JSON.stringify(myObj));

The simplified process looks like this:

Hope this is of some help,

Erik

Hi Nate,

I feel you regarding search capabilities on sites and forums. So until OL manages to add that, here is a tip that I use all the time.

JSON site:http://learn.objectiflune.com/en-us/planetpress-connect/howto

Typing the above in Google will get you all pages using tags or words like JSON.

Regards,

S

Good trick, Sharne. Thanks for sharing.