Read Data Field
ActionsAbout
Tags
(1)GitHub Action to extract content from data files. How it works:
- Provide a file path to some data (supports
JSON,JSON5,JSONC,YAMLandTOML) - Provide a field to index the data, like
version,author.nameorkeywords[0] - Read the output with
${{ steps.<step-id>.outputs.result }}
Jump to:
Add this action to your workflow by referencing it in your .github/workflows/*.yml file:
- uses: seaofvoices/read-data-field-action@v1
id: <enter-an-id-to-refer-to>
with:
file: package.json
field: version| Input | Description | Required |
|---|---|---|
file |
Path to the data file to read | Yes |
field |
Dot-separated field path to extract (e.g., scripts.build, database.host) |
Yes |
The field input uses dot-notation syntax to traverse nested data structures. You can access object properties, array elements.
- use
.to index by a property name - use
[<integer>]to index an array. Replace<integer>with a valid 0-based array index, e.g.[0]to index the first element.
Here are a few examples of field paths that can be used. Note that the examples are using JSON data, but these are valid for any supported data format.
| Field Path | Data | Result |
|---|---|---|
version |
{"version": "1.0.0"} |
"1.0.0" |
author.name |
{"author": {"name": "John"}} |
"John" |
scripts.build |
{"scripts": {"build": "rollup"}} |
"rollup" |
keywords[0] |
{"keywords": ["json", "parser"]} |
"json" |
keywords[1] |
{"keywords": ["json", "parser"]} |
"parser" |
authors[0].name |
{"authors": [{"name": "Alice"}, {"name": "Bob"}]} |
"Alice" |
config.servers[1].host |
{"config": {"servers": [{"host": "dev"}, {"host": "prod"}]}} |
"prod" |
Escape special characters using backslashes \.
| character | usage | data example | field example | result |
|---|---|---|---|---|
. |
Index a property that contains a . |
{ "luau-lsp.platform.type": "roblox" } |
luau-lsp\.platform\.type |
roblox |
\ |
Index a property that contains a \ |
{ "a\b": false } |
a\\b |
false |
[ |
Index a property that contains a [ |
{ "[dev]": "localhost" } |
\[dev] |
localhost |
The action produces 2 output values. Look at the examples to see how to read them.
| Output | Description |
|---|---|
result |
The extracted data in its original type |
result_json |
The extracted data encoded as JSON string |
- name: Read package version
id: package-info
uses: seaofvoices/read-data-field-action@v1
with:
file: package.json
field: version
- name: Use the version
run: echo "Package version is ${{ steps.package-info.outputs.result }}"- name: Read build script
id: build-script
uses: seaofvoices/read-data-field-action@v1
with:
file: package.json
field: scripts.build
- name: Read nested YAML configuration
id: config
uses: seaofvoices/read-data-field-action@v1
with:
file: config.yaml
field: database.host- name: Read Cargo package name
id: cargo-info
uses: seaofvoices/read-data-field-action@v1
with:
file: Cargo.toml
field: package.nameThe action supports multiple data formats and uses intelligent parsing:
- JSON (
.json) - Standard JSON format - JSON5 (
.json5) - JSON5 with comments and trailing commas - JSONC (
.json) - JSON with comments (falls back if standard JSON parsing fails) - YAML (
.yml,.yaml) - YAML format - TOML (
.toml) - TOML format
The parser automatically detects the format based on file extension and tries all available parsers.
This project is available under the MIT license. See LICENSE.txt for details.
Read Data Field is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.