Tutorial: Build a function using a generic job
This tutorial provides step-by-step instructions to use a generic job to develop a function that converts YAML documents into JSON format.
Prerequisites
Before continuing with this tutorial, ensure you have completed the following prerequisites:
Create a function for conversion
Open the LEARN_DEV project in Snoweaver with the LEARN_DEV_DEVELOPER role.
Open the Functions page.
Create the following function.
Name:
yaml_to_json
Definition:
def yaml_to_json(input: str): from ruamel.yaml import YAML import json yaml = YAML(typ='safe') return json.dumps(yaml.load(input))
Validator - Jinja Template:
{{ yaml_to_json(''' --- doe: "a deer, a female deer" ray: "a drop of golden sun" pi: 3.14159 xmas: true ''') }}
Note
You do not need to specify the ruamel.yaml package, as it is included among the pre-loaded Packages.
Test the function.
Save the function.
Create a generic job
Open the Jobs page
Apply the following configuration:
Name: yaml_to_json Job Type: Generic Instance Type: Function Functions: yaml_to_json Output Format: Json
Specify the following job vairable:
Name
Type
Test Value
yaml_doc
Text
a: b: 2
Use the following Jinja template for specifying the job Output:
{{ yaml_to_json(_vars.yaml_doc) }}
Test the template to validate the output.
Click Make a Test Call to test the job. The output should match the results produced in the preceding step.
Save the job.
Click Build to build a job instance.