Home

Awesome

YAML/JSON/XML action (Deprecated)

This GitHub action is deprecated and no longer maintained starting from 2022/10/21. Please use Data Format Converter Action instead. It is faster, can be run on any OS and supports much more data formats than this one.

GitHub release (latest SemVer including pre-releases) Unit Tests Security Tests Total alerts Language grade: JavaScript Known Vulnerabilities Maintainability Test Coverage

Converts YAML/JSON/XML file formats interchangeably.

Inputs

NameRequiredDescriptionPossible values
pathYesPath to the file to be converted<Path>
fromYesFormat of a filejson, xml, yaml
toYesFormat of a file as a resultjson, xml, yaml

Outputs

NameRequiredDescription
dataYesResult in a format defined in to argument

Example usage

Prerequisites

Let's imagine we need to transform yaml file into xml format and json file into yaml format.

---
version: '3.7'
services:
  mongo:
    image: mongo:4.2.3-bionic
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: abc123
    networks:
      - test-network

networks:
  test-network:
    name: test-network
    driver: bridge
{
    "name": "John Doe",
    "age": 32,
    "hobbies": ["Music", "PC Games"]
}

Workflow configuration

name: Convert

on: push

jobs:
  converter:
    name: Run converter
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: fabasoad/yaml-json-xml-converter-action@main
        id: yaml2xml
        with:
          path: 'docker-compose.yml'
          from: 'yaml'
          to: 'xml'
      - name: Print yaml2xml result
        run: echo "${{ steps.yaml2xml.outputs.data }}"
      - uses: fabasoad/yaml-json-xml-converter-action@main
        id: json2yaml
        with:
          path: 'package.json'
          from: 'json'
          to: 'yaml'
      - name: Print json2yaml result
        run: echo "${{ steps.json2yaml.outputs.data }}"

Result

Result

Hint: If you define the same format for from and to parameters you can use this action to read the file :wink: