Skip to content

Examples

Alexis Bridoux edited this page Oct 15, 2025 · 6 revisions

Use these commands with the People files in the Playground. The commands work regardless of the file format you choose with the -i | --input option: People.json, People.plist, People.yml or People.xml. The JSON version is provided below.

JSON version of the People files
{
  "Tom" : {
    "age" : 68,
    "hobbies" : [
      "cooking",
      "guitar"
    ],
    "height" : 175
  },
  "Robert" : {
    "age" : 23,
    "hobbies" : [
      "video games",
      "party",
      "tennis"
    ],
    "running_records" : [
      [
        10,
        12, 9,
        10
      ],
      [ 9,
        12,
        11
      ]
    ],
    "height" : 181
  },
  "Suzanne" : {
    "job" : "actress",
    "movies" : [
      {
        "title" : "Tomorrow is so far",
        "awards" : "Best speech for a silent movie"
      },
      {
        "title" : "Yesterday will never go",
        "awards" : "Best title"
      },
      {
        "title" : "What about today?"
      }
    ]
  }
}

Read

❖ Output Tom's height: 175.

scout read "Tom.height" -i People.json -f json

❖ Output Tom's first hobby: cooking.

scout read "Tom.hobbies[0]" -i People.xml -f xml

❖ Output Tom's last hobby: guitar.

scout read "Tom.hobbies[-1]" -i People.xml -f xml

❖ Output Suzanne first movie title: Tomorrow is so far.

scout read "Suzanne.movies[0].title" -i People.yml -f yaml

❖ Output Suzanne second movie title from the end: "Yesterday will never go".

scout read "Suzanne.movies[-2].title" -i People.yml -f yaml

❖ Output Robert running records second record first value: 9.

scout read "Robert.running_records[1][0]" -i People.json -f json

❖ Output Tom dictionary.

scout read "Tom" -i People.json -f json
Output
{
  "age" : 68,
  "hobbies" : [
    "cooking",
    "guitar"
  ],
  "height" : 175
}

Get Dictionary or Array Count

Get a dictionary or an array count with the [#] symbol.

❖ Get people count: 3.

scout read "[#]" -i People.plist

❖ Get Suzanne's movies count: 3.

scout read "Suzanne.movies[#]" -i People.xml -f xml

Get a Dictionary Keys

You can list a dictionary's keys with the {#} symbol. The keys are returned as an array.

❖ Get Tom dictionary keys list.

scout read -i People.yml -f yaml "Tom{#}"

Useful to iterate over a dictionary with the --csv-sep export option:

keys=(`scout read -i People.json -f json "Tom{#}" —csv-sep " "`)

for key in $keys;  do
    scout read -i People.json -f json ”Tom.$key";
done

Get a Group Sample

Array Slicing

❖ Get Robert first two hobbies.

scout read -i People.json -f json "Robert.hobbies[:1]"

❖ Get Robert last two hobbies.

scout read -i People.yml -f yaml "Robert.hobbies[-2:]".

❖ Get Suzanne movies titles

scout read -i People.plist -f plist "Suzanne.movies[:].title"

Dictionary Filtering

❖ Get Tom keys beginning by "h".

scout read -i People.json -f json "Tom.#h.*#"

❖ Get Tom and Robert hobbies.

scout read -i People.xml -f xml "#Tom|Robert#.hobbies"

Mixing Slicing and Filtering

❖ Get Tom and Robert first two hobbies.

scout read -i People.yml -f yaml "#Tom|Robert#.hobbies[:1]"

Set

❖ Set Robert age to: 60.

scout set "Robert.age=60" -i People.plist -f plist

❖ Set Suzanne second movie title to: "Never gonna die".

scout set "Suzanne.movies[1].title"="Never gonna die" -i People.yml -f yaml

❖ Set Tom last hobby to "play music". Set Suzanne job to: comedian.

scout set \
"Tom.hobbies[-1]=play music" \
"Suzanne.job=comedian" \
-I People.plist

❖ Set Robert running records first record third value to: 15.

scout set "Robert.running_records[0][2]=15" -i People.xml -f xml

❖ Set Tom height to the String value: 165.

scout set "Tom.height=/165/" -i People.json -f json

❖ Set Tom height to the Real value: 165 (only useful for Plist files).

scout set "Tom.height=~165~" -i People.plist -f plist

❖ Set Tom height key name to "centimeters

scout set "Tom.height=#centimeters#" -i People.json  -f json

Delete

❖ Delete Robert second hobby: party.

scout delete "Robert.hobbies[1]" -i People.xml -f xml

❖ Delete Tom last hobby and Suzanne second movie awards.

scout delete \
"Tom.hobbies[-1]" \
"Suzanne.movies[1].awards" \
-I People.json

❖ Delete Robert hobbies array.

scout delete "Robert.hobbies" -i People.yml -f yaml

❖ Delete all Tom hobbies and recursively the hobbies array.

scout delete "Tom.hobbies[:]" -ir People.yml -f yaml

Delete a Group Sample

Array Slicing

❖ Delete Robert first two hobbies.

scout delete -i People.json -f json "Robert.hobbies[:1]"

❖ Delete Robert last two hobbies.

scout delete -i People.xml -f xml "Robert.hobbies[-2:]"

❖ Delete Suzanne movies titles.

scout delete -i People.plist -f plist "Suzanne.movies[:].title"

❖ Delete Suzanne movies titles and remove the last movie element as it only as a "title" key with the -r|--recursive flag.

scout delete -ir People.plist "Suzanne.movies[:].title"

Dictionary Filtering

❖ Delete Tom keys beginning by "h"

scout delete -i People.xml -f xml "Tom.#h.*#"

❖ Delete Tom and Robert hobbies.

scout delete -i People.plis -f plist "#Tom|Robert#.hobbies"

Mixing Slicing and Filtering

❖ Delete Tom and Robert first two hobbies.

scout delete -i People.json -f json "#Tom|Robert#.hobbies[:1]"

❖ Delete Tom and Robert first two hobbies and Tom hobbies key recursively

scout delete -ir People.json -f json "#Tom|Robert#.hobbies[:1]"

Add

❖ Add a surname for Robert: Bob.

scout add "Robert.surname"=Bob -i People.xml -f xml

❖ Add a movie to Suzanne's movies with the title: "Never gonna die".

scout add "Suzanne.movies[#].title"="Never gonna die" -I People.json

❖ Add a new surname for Robert: Bob. Add a new hobby for Tom at the end of the hobbies array: sleeping.

scout add \
"Robert.surname=Bob" \
"Tom.hobbies[#]=sleeping" \
-i People.plist -f plist

❖ Add a new value at the end of the array to Robert running records second record.

scout add "Robert.running_records[1][#]"=20 -I People.yml

❖ Add a new record to Robert running records and add a new value into it: 15.

scout add \
"Robert.running_records[#]=[]" \
"Robert.running_records[-1][0]=15" \
-i People.json -f json

❖ Add a new String value at the end the array to Robert running records first record.

scout add "Robert.running_records[0][#]=/15/" -i People.plist -f plist

List Paths

❖ List all the paths in the file People.plist.

scout paths -i People.plist -f plist
Output
Robert
Robert.age
Robert.height
Robert.hobbies
Robert.hobbies[0]
Robert.hobbies[1]
Robert.hobbies[2]
Robert.running_records
Robert.running_records[0]
Robert.running_records[0][0]
Robert.running_records[0][1]
Robert.running_records[0][2]
Robert.running_records[0][3]
Robert.running_records[1]
Robert.running_records[1][0]
Robert.running_records[1][1]
Robert.running_records[1][2]
Suzanne
Suzanne.job
Suzanne.movies
Suzanne.movies[0]
Suzanne.movies[0].awards
Suzanne.movies[0].title
Suzanne.movies[1]
Suzanne.movies[1].awards
Suzanne.movies[1].title
Suzanne.movies[2]
Suzanne.movies[2].title
Tom
Tom.age
Tom.height
Tom.hobbies
Tom.hobbies[0]
Tom.hobbies[1]

Target Single or Group Values

❖ List all the paths leading to single values in the file People.xml.

scout paths -i People.xml -f xml --single
Output
Robert.age
Robert.height
Robert.hobbies[0]
Robert.hobbies[1]
Robert.hobbies[2]
Robert.running_records[0][0]
Robert.running_records[0][1]
Robert.running_records[0][2]
Robert.running_records[0][3]
Robert.running_records[1][0]
Robert.running_records[1][1]
Robert.running_records[1][2]
Suzanne.job
Suzanne.movies[0].awards
Suzanne.movies[0].title
Suzanne.movies[1].awards
Suzanne.movies[1].title
Suzanne.movies[2].title
Tom.age
Tom.height
Tom.hobbies[0]
Tom.hobbies[1]

❖ List all the paths leading to group values in the file People.xml.

scout paths -i People.xml -f xml --group
Output
Robert
Robert.hobbies
Robert.running_records
Robert.running_records[0]
Robert.running_records[1]
Suzanne
Suzanne.movies
Suzanne.movies[0]
Suzanne.movies[1]
Suzanne.movies[2]
Tom
Tom.hobbies

Initial Path

❖ List all the paths in the file People.yml in Robert dictionary.

scout paths "Robert" -i People.yml -f xml
Output
Robert.age
Robert.height
Robert.hobbies
Robert.hobbies[0]
Robert.hobbies[1]
Robert.hobbies[2]
Robert.running_records
Robert.running_records[0]
Robert.running_records[0][0]
Robert.running_records[0][1]
Robert.running_records[0][2]
Robert.running_records[0][3]
Robert.running_records[1]
Robert.running_records[1][0]
Robert.running_records[1][1]
Robert.running_records[1][2]

❖ List all the paths in the file People.yml in Robert and Tom dictionary.

scout paths -i People.yml -f yaml "#Robert|Tom#"
Output
Robert
Robert.age
Robert.height
Robert.hobbies
Robert.hobbies[0]
Robert.hobbies[1]
Robert.hobbies[2]
Robert.running_records
Robert.running_records[0]
Robert.running_records[0][0]
Robert.running_records[0][1]
Robert.running_records[0][2]
Robert.running_records[0][3]
Robert.running_records[1]
Robert.running_records[1][0]
Robert.running_records[1][1]
Robert.running_records[1][2]
Tom
Tom.age
Tom.height
Tom.hobbies
Tom.hobbies[0]
Tom.hobbies[1]

❖ List all the paths leading to Suzanne's movies titles in the file People.yml.

scout paths -i People.yml -f yaml "Suzanne.movies[:].title"
Output
Suzanne.movies[0].title
Suzanne.movies[1].title
Suzanne.movies[2].title

Filter the Keys

❖ List all the paths leading to a key "hobbies" in the file People.json.

scout paths -i People.json -f json -k "hobbies"
Output
Robert.hobbies
Robert.hobbies[0]
Robert.hobbies[1]
Robert.hobbies[2]
Tom.hobbies
Tom.hobbies[0]
Tom.hobbies[1]

❖ List all the paths leading to a key starting with "h" in the file People.json.

scout paths -i People.json -f json-k "h.*"
Output
Robert.height
Robert.hobbies
Robert.hobbies[0]
Robert.hobbies[1]
Robert.hobbies[2]
Tom.height
Tom.hobbies
Tom.hobbies[0]
Tom.hobbies[1]

Filter the Values

❖ List the paths whose value is below 70.

scout paths -i People.plist -f plist -v "value < 70"
Output
Robert.age
Robert.running_records[0][0]
Robert.running_records[0][1]
Robert.running_records[0][2]
Robert.running_records[0][3]
Robert.running_records[1][0]
Robert.running_records[1][1]
Robert.running_records[1][2]
Tom.age

❖ List the paths whose value is greater than or equal to 20 and lesser than 70.

scout paths -i People.plist -f plist -v "value >= 20 && value < 70"
Output
Robert.age
Tom.age

❖ List the paths whose value starts with "guit" (case sensitive).

scout paths -i People.json -f json -v "value hasPrefix 'guit'"
Output
Tom.hobbies[1]

❖ List the paths whose value starts with "guit" or are greater than 20 (case sensitive).

scout paths -i People.json -f json -v "value hasPrefix 'guit'" -v "value > 20"
Output
Robert.age
Robert.height
Tom.age
Tom.height
Tom.hobbies[1]

Mixing Up

❖ List paths leading to Robert hobbies that contain the word "game".

scout paths -i People.yml -f yaml "Robert.hobbies" -v "value contains 'games'"
Output
Robert.hobbies[0]

❖ List paths leading to Robert or Tom hobbies array (group values).

scout paths -i People.yml -f yaml "#Tom|Robert#" -k "ho.*" --group
Output
Robert.hobbies
Tom.hobbies

❖ List paths leading to Suzanne's movies titles that contains the word "today".

scout paths -i People.json -f json "Suzanne.movies[:].title" -v "value contains 'today'"
Output
Suzanne.movies[2].title

Clone this wiki locally