YAML parse transform action

Use case

An API has returned a YAML formatted string and you would like to convert it to a JSON object.

Overview

Parses a YAML string and returns the resulting data structure in JSON.

Parameters

Parameter
Description
Required

YAML Input

The YAML string to parse.

This transform is utilizing the yaml_parse filter, which will only work with one document.

If your YAML string contains multiple documents you should process them individually.

Usage

Example: Parsing a YAML string

YAML input:

version: 2.1

# Define the jobs we want to run for this project
jobs:
  build:
    docker:
      - image: cimg/base:2023.03
    steps:
      - checkout
      - run: echo "this is the build job"
  test:
    docker:
      - image: cimg/base:2023.03
    steps:
      - checkout
      - run: echo "this is the test job"

# Orchestrate our job run sequence
workflows:
  build_and_test:
    jobs:
      - build
      - test

Results output

Result of example:

{
  "jobs": {
    "test": {
      "steps": [
        "checkout",
        {
          "run": "echo \"this is the test job\""
        }
      ],
      "docker": [
        {
          "image": "cimg/base:2023.03"
        }
      ]
    },
    "build": {
      "steps": [
        "checkout",
        {
          "run": "echo \"this is the build job\""
        }
      ],
      "docker": [
        {
          "image": "cimg/base:2023.03"
        }
      ]
    }
  },
  "version": 2.1,
  "workflows": {
    "build_and_test": {
      "jobs": [
        "build",
        "test"
      ]
    }
  }
}

Last updated

Was this helpful?