Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
file-text

GitHub Action

create-json

1.1.2

create-json

file-text

create-json

Create an JSON file from secret or a string of a json

Installation

Copy and paste the following snippet into your .yml file.

              

- name: create-json

uses: jsdaniell/[email protected]

Learn more about this action in jsdaniell/create-json

Choose a version

create-json

Create a .json file dynamically on your workflow

Example of the output on the .json file created:

{
    "name":"jsdaniell",
    "password":"mypass"
}

How to use

You can define a json structure on the secrets of your repository:

{
    "name":"jsdaniell",
    "password":"mypass"
}

MY_JSON (Secrets variables can be configured on repository settings > Secrets)

and use in this way:

    - name: create-json
      id: create-json
      uses: jsdaniell/[email protected]
      with:
        name: "credentials.json"
        json: ${{ secrets.MY_JSON }}

Or just declare a string of a json on the property json like:

    - name: create-json
      id: create-json
      uses: jsdaniell/[email protected]
      with:
        name: "new-json-file.json"
        json: '{"name":"jsdaniell", "password":"mypass"}'

The json have to be inside a string.

You also can save the json on a subdirectory using the property dir:

    - name: create-json
      id: create-json
      uses: jsdaniell/[email protected]
      with:
        name: "credentials.json"
        json: ${{ secrets.CREDENTIALS_JSON }}
        dir: 'src/'

Remember that when you create a .json file, the file was not commited, you have to commit the file if you will use the HEAD branch with the file to push the repository to other service, like deploy to heroku or other platforms.

If you want to create more than one json files, you have to specify different IDs for the action like:

    - name: create-json
      id: create-json-1 # First ID
      uses: jsdaniell/[email protected]
      with:
        name: "credentials.json"
        json: ${{ secrets.CREDENTIALS_JSON }}
        dir: 'src/'
    - name: create-json
      id: create-json-2  # Second ID
      uses: jsdaniell/[email protected]
      with:
        name: "other.json"
        json: '{"name":"jsdaniell", "password":"mypass"}'
        dir: 'src/'

Contribute

You can submit an issue or PR anytime for the improvement this action!