A Jenkins plugin that is Pipeline compatible for json related help functions
Can convert json strings to a usable object and vice versa.
- Jenkins 1.639 or newer
- Jenkins Pipeline Plugin
Once installed, you can use it in a pipeline in-line script or Jenkinsfile. For how to use it, see below or use the Snippet Generator.
Converts a JSON String to an Object.
def fooBar = writeObjectFromJson '{"foo" : "bar"}'
def fooValue = fooBar.foo
You can supply it an object and it will write out a correct json, or return null.
Usage
class Person {
def name;
def age;
}
node {
def joost = new Person()
joost.name = 'joost'
joost.age = 10
def jsonString = writeObjectToJson(joost)
echo "jsonString=$jsonString"
}
It will print out the following:
jsonString={"name":"joost","age":10}