How can I convert a groovy script to JSON for REST API usage ?

In order to upload a groovy script via the REST API, the script must be encoded within a JSON payload.

The following Python script can be used as a starting point to achieve this:

import json

with open("testscript.groovy", "r") as inputfile:
filedata =
jsondata = {}
jsondata['name'] = 'testscript'
jsondata['type'] = 'groovy'
jsondata['content'] = filedata

with open("test.json", "w") as outputfile:

(Change testscript.groovy to be the source script file and test.json to be the required output file)

This will produce an output file with the correct payload to be used directly within the REST API call. The script will be called testscript within the subsequent API calls, but this can also be amended as necessary within the script or payload.

Have more questions? Submit a request


Article is closed for comments.