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.
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.
There are several ways to work with JSON data from within Workflow. Below a few techniques I use on a regular basis:
Create File plugin to construct and return JSON
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:
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: