-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Faeka Ansari <faeka6@gmail.com> docs Signed-off-by: Faeka Ansari <faeka6@gmail.com> nit docs Signed-off-by: Faeka Ansari <faeka6@gmail.com>
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
docs/docs/50-user-guide/60-reference-docs/30-promotion-steps/json-parse.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
sidebar_label: json-parse | ||
description: Parses a JSON string and extracts values based on specified expressions. | ||
--- | ||
|
||
# `json-parse` | ||
|
||
`json-parse` is a utility step that parses a JSON string and extracts values using [expr-lang][] expressions. | ||
|
||
## Configuration | ||
|
||
| Name | Type | Required | Description | | ||
|------|------|----------|-------------| | ||
| `path` | `string` | Y | Path to a JSON file. This path is relative to the temporary workspace that Kargo provisions for use by the promotion process. | | ||
| `outputs` | `[]object` | Y | A list of rules for extracting values from the parsed JSON. | | ||
| `outputs[].name` | `string` | Y | The name of the output variable. | | ||
| `outputs[].fromExpression` | `string` | Y | An [expr-lang](https://expr-lang.org/) expression that can extract the value from the JSON file. Note that this expression should not be offset by `${{` and `}}`. See examples for more details. | | ||
|
||
## Expressions | ||
|
||
The `fromExpression` field supports [expr-lang](https://expr-lang.org/) expressions. | ||
|
||
:::note | ||
Expressions should _not_ be offset by `${{` and `}}` to prevent pre-processing evaluation by Kargo. The `json_parser` step itself will evaluate these expressions. | ||
::: | ||
|
||
A `outputs` object (a `map[string]any`) is available to these expressions. It is structured as follows: | ||
|
||
| Field | Type | Description | | ||
|-------|------|-------------| | ||
| `outputs` | `map[string]any` | The parsed JSON object. | | ||
|
||
## Outputs | ||
|
||
The `json_parser` step produces the outputs described by the `outputs` field in its configuration. | ||
|
||
## Examples | ||
|
||
### Basic Usage | ||
|
||
This example extracts values from a JSON object representing a user. | ||
|
||
```yaml | ||
steps: | ||
# ... | ||
- uses: json_parser | ||
as: parse-user | ||
config: | ||
path: './sample.json' | ||
outputs: | ||
- name: userName | ||
fromExpression: parsed.name | ||
- name: userAge | ||
fromExpression: parsed.age | ||
- name: userCity | ||
fromExpression: parsed.address.city | ||
``` | ||
Given the sample input JSON: | ||
```json | ||
{ | ||
"name": "Alice", | ||
"age": 30, | ||
"address": { | ||
"city": "New York" | ||
} | ||
} | ||
``` | ||
|
||
The step would produce the following outputs: | ||
|
||
| Name | Type | Value | | ||
|------|------|-------| | ||
| `userName` | `string` | `Alice` | | ||
| `userAge` | `int` | `30` | | ||
| `userCity` | `string` | `New York` | |