Serialize To JSON

Action ID: roadiehq:utils:serialize:json
NPM Package:

@roadiehq/scaffolder-backend-module-utils

Description

Allows performing serialization on an object

Input Schema

PropertyTypeDescriptionRequired
dataobject-
spacestring-
replacerarray-

Output Schema

PropertyTypeDescriptionRequired
serializedstring-

Usage Examples

Serialize deployment parameters for template injection

Use this to turn deployment parameters into a compact JSON string that can be injected into files in your skeleton. The serialized output is passed into fetch:template as a template value.

Copy
steps:
  - id: serialize-deploy-params
    action: roadiehq:utils:serialize:json
    input:
      data:
        service: ${{ parameters.componentId }}
        image:
          repository: ghcr.io/acme/${{ parameters.componentId }}
          tag: ${{ parameters.imageTag }}
        env:
          NODE_ENV: production
          LOG_LEVEL: ${{ parameters.logLevel }}
        featureFlags:
          - audit
          - metrics
        rollout:
          strategy: blue-green
          maxUnavailable: 1

  - id: fetch-base
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        deploymentJson: ${{ steps.serialize-deploy-params.outputs.serialized }}

Pretty-print application settings.json

Use this to generate a human-readable JSON config with two-space indentation. The output can be written into a settings.json template via fetch:template.

Copy
steps:
  - id: serialize-settings
    action: roadiehq:utils:serialize:json
    input:
      data:
        appName: ${{ parameters.appName }}
        apiBaseUrl: https://api.internal.acme.com
        oauth:
          clientId: ${{ parameters.oauthClientId }}
          scopes:
            - openid
            - profile
            - email
        features:
          darkMode: true
          betaBanner: false
      space: "  "

  - id: fetch-project
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        settingsJson: ${{ steps.serialize-settings.outputs.serialized }}

Whitelist and serialize public config without secrets

Use this to whitelist only safe fields using replacer, excluding secrets from the serialized string. The result is formatted for commit and used in templates via fetch:template.

Copy
steps:
  - id: serialize-public-config
    action: roadiehq:utils:serialize:json
    input:
      data:
        serviceName: ${{ parameters.componentId }}
        env: ${{ parameters.environment }}
        regions:
          - us-east-1
          - eu-central-1
        secretToken: ${{ parameters.secretToken }}
        apiKeys:
          datadog: ${{ parameters.datadogApiKey }}
      replacer:
        - serviceName
        - env
        - regions
      space: "  "

  - id: fetch-template
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        publicConfigJson: ${{ steps.serialize-public-config.outputs.serialized }}

Serialize a subset for a single-line annotation

Use this to serialize only selected fields into a compact JSON string suitable for a single-line annotation or label. The compact output is provided to fetch:template.

Copy
steps:
  - id: serialize-annotation
    action: roadiehq:utils:serialize:json
    input:
      data:
        name: ${{ parameters.componentId }}
        rules:
          - allow: read
            match: /.*
          - allow: write
            match: ^/public
        expiresAt: ${{ parameters.expiry }}
        owner: ${{ parameters.owner }}
      replacer:
        - rules
        - expiresAt

  - id: fetch-catalog
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        rulesAnnotation: ${{ steps.serialize-annotation.outputs.serialized }}

Deterministic package manifest with key order and tab indentation

Use replacer to control which keys are included and their order, and use a tab character for indentation. This produces a deterministic package manifest string for use in fetch:template.

Copy
steps:
  - id: serialize-package-json
    action: roadiehq:utils:serialize:json
    input:
      data:
        name: ${{ parameters.componentId }}
        version: 0.1.0
        description: ${{ parameters.description }}
        dependencies:
          express: ^4.19.2
          pino: ^9.0.0
        devDependencies:
          typescript: ^5.6.3
          jest: ^29.7.0
        scripts:
          build: tsc -p .
          test: jest
        private: true
      replacer:
        - name
        - version
        - description
        - dependencies
        - devDependencies
        - scripts
        - private
      space: "\t"

  - id: fetch-node-app
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        packageJsonString: ${{ steps.serialize-package-json.outputs.serialized }}