JSONata JSON Transform

Action ID: roadiehq:utils:jsonata:json:transform
NPM Package:

@roadiehq/scaffolder-backend-module-utils

Description

Allows performing JSONata operations and transformations on a JSON file in the workspace.

Input Schema

PropertyTypeDescriptionRequired
asstring-
pathstring-
spacestring-
replacerarray-
expressionstring-

Output Schema

PropertyTypeDescriptionRequired
resultany-

Usage Examples

Extract a service summary from package.json

Extracts key metadata from package.json into a compact object. Use this when you need to compute values from existing files earlier in the workflow after fetch:template.

Copy
steps:
  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeletons/node-service
      targetPath: .
      values:
        name: ${{ parameters.name }}

  - id: summarize-package
    action: roadiehq:utils:jsonata:json:transform
    input:
      path: package.json
      expression: |
        {
          "name": name,
          "version": version,
          "dependenciesCount": dependencies ? $count($keys(dependencies)) : 0,
          "devDependenciesCount": devDependencies ? $count($keys(devDependencies)) : 0,
          "nodeEngine": engines.node ? engines.node : ">=18"
        }
      as: object

Select and format production endpoints from environments.json

Filters prod environments and returns a pretty-printed JSON string with only the name and url fields. Use this to produce a curated JSON snippet you can write or publish after fetch:template.

Copy
steps:
  - id: fetch-config
    action: fetch:template
    input:
      url: ./skeletons/service-with-envs
      targetPath: .
      values:
        serviceId: ${{ parameters.serviceId }}

  - id: prod-endpoints
    action: roadiehq:utils:jsonata:json:transform
    input:
      path: config/environments.json
      expression: |
        $map(environments[type="${{ parameters.targetEnv | default('prod') }}"], function($e) {
          {"name": $e.name, "url": $e.url}
        })
      replacer:
        - name
        - url
      space: "2"
      as: string

Generate .env content from a JSON config

Builds .env formatted content from an env object in config/app.json. Use when you need to derive a .env file from structured config produced by fetch:template.

Copy
steps:
  - id: fetch-app
    action: fetch:template
    input:
      url: ./skeletons/web-app
      targetPath: .
      values:
        region: ${{ parameters.region }}

  - id: env-from-json
    action: roadiehq:utils:jsonata:json:transform
    input:
      path: config/app.json
      expression: |
        $join(
          $map($keys(env), function($k) { $k & "=" & env[$k] }),
          "\n"
        )
      as: string

Compute Docker image tags from build metadata

Computes a list of semantic version tags from a build.json version. Use this to consistently generate tags used in later steps of your pipeline after fetch:template.

Copy
steps:
  - id: fetch-build
    action: fetch:template
    input:
      url: ./skeletons/containerized-service
      targetPath: .
      values:
        imageName: ${{ parameters.imageName }}

  - id: compute-tags
    action: roadiehq:utils:jsonata:json:transform
    input:
      path: ci/build.json
      expression: |
        (
          $v := $split(version, ".");
          [version, $v[0] & "." & $v[1], $v[0]]
        )
      as: object

Sanitize a config by whitelisting fields

Returns the full JSON document but stringified with only safe top-level keys included. Use this to produce a redacted config string you can store or publish, after fetch:template.

Copy
steps:
  - id: fetch-config-base
    action: fetch:template
    input:
      url: ./skeletons/service-config
      targetPath: .
      values:
        serviceName: ${{ parameters.name }}

  - id: redact-config
    action: roadiehq:utils:jsonata:json:transform
    input:
      path: config/service.json
      expression: "$" # return the whole document
      replacer:
        - serviceName
        - public
        - features
        - endpoints
      space: "2"
      as: string