From f5d3e0c2202b035ff87720bbf5588df9a1b2f0db Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 00:30:37 -0300 Subject: [PATCH] Add outputs as tabs Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.md | 100 ++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index 3efe24a4..35971e27 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -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