Skip to content

Commit

Permalink
Add outputs as tabs
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Ribeiro-Dantas <[email protected]>
  • Loading branch information
mribeirodantas committed Jun 27, 2023
1 parent 5f57613 commit f5d3e0c
Showing 1 changed file with 75 additions and 25 deletions.
100 changes: 75 additions & 25 deletions docs/basic_training/channels.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,37 +604,87 @@ Channel
We can also easily parse the JSON file format using the `splitJson` channel operator.

The `splitJson` operator supports JSON arrays:
```groovy linenums="1"
Channel
.of('["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]')
.splitJson()
.view { "Item: ${it}" }
```

=== "Source code"

```groovy linenums="1"
Channel
.of('["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]')
.splitJson()
.view { "Item: ${it}" }
```

=== "Output"

```console
Item: Sunday
Item: Monday
Item: Tuesday
Item: Wednesday
Item: Thursday
Item: Friday
Item: Saturday
```

JSON objects:
```groovy linenums="1"
Channel
.of('{"player": {"name": "Bob", "height": 180, "champion": false}}')
.splitJson()
.view { "Item: ${it}" }
```

=== "Source code"

```groovy linenums="1"
Channel
.of('{"player": {"name": "Bob", "height": 180, "champion": false}}')
.splitJson()
.view { "Item: ${it}" }
```

=== "Output"

```console
Item: [key:player, value:[name:Bob, height:180, champion:false]]
```

And even a JSON array of JSON objects!
```groovy linenums="1"
Channel
.of('[{"name": "Bob", "height": 180, "champion": false}, \
{"name": "Alice", "height": 170, "champion": false}]')
.splitJson()
.view { "Item: ${it}" }
```

=== "Source code"

```groovy linenums="1"
Channel
.of('[{"name": "Bob", "height": 180, "champion": false}, \
{"name": "Alice", "height": 170, "champion": false}]')
.splitJson()
.view { "Item: ${it}" }
```

=== "Output"

```console
Item: [name:Bob, height:180, champion:false]
Item: [name:Alice, height:170, champion:false]
```

Files containing JSON content can also be parsed:
```groovy linenums="1"
Channel
.fromPath('file.json')
.splitJson()
.view { "Item: ${it}" }
```

=== "Source code"

```groovy linenums="1"
Channel
.fromPath('file.json')
.splitJson()
.view { "Item: ${it}" }
```

=== "file.json"

```json
[{"name": "Bob", "height": 180, "champion": false}, {"name": "Alice", "height": 170, "champion": false}]
```

=== "Output"

```console
Item: [name:Bob, height:180, champion:false]
Item: [name:Alice, height:170, champion:false]
```

### YAML

Expand Down

0 comments on commit f5d3e0c

Please sign in to comment.