Thanks to visit codestin.com
Credit goes to Github.com

Skip to content
Michael Dykman edited this page Oct 5, 2016 · 2 revisions

command line interface

These example will use files which are stored in the repository at src/test/resources

We assume that jtl has been installed correctly and is available at the command line.

Use src/test/resources as the current directory.

The file people.json describes an array of objects

[{
   "name": "Jasmine Daugherty",
   "id": "558a0750ed9439f04ce78be3",
   "eyeColor": "green",
   "element": "fire"
}, {
   "name": "Boyd Atkinson",
   "id": "558a0750dc8657c510cc05e1",
   "eyeColor": "brown",
   "element": "ice"
}, {
   "name": "Petty Shelton",
   "id": "558a075036f23b391dad96db",
   "eyeColor": "blue",
   "element": "candy"
}, {
   "name": "Byrd Hebert",
   "id": "558a0750960cdff814f14bb9",
   "eyeColor": "green",
   "element": "fire"
}, {
   "name": "Parks Berg",
   "id": "558a0750dee279e5ca3ed92c",
   "eyeColor": "green",
   "element": "ice"
}, {
   "name": "Teri Stevenson",
   "id": "558a0750f34b44ee5754a2bd",
   "eyeColor": "blue",
   "element": "candy"
}, {
   "name": "Dorothea Munoz",
   "id": "558a0750a941ec9ba32b8ff9",
   "eyeColor": "brown",
   "element": "ice"
}]

some simple JPath expressions

We are going to use jtl's -e switch to specify JPath/JTL expressions directly on the command line

get a count of the number of objects

 $ jtl -e "count()" people.json
7

enumerate the available keys

 $ jtl -e "keys()" people.json
 [ "name", "id", "eyeColor", "element" ]

obtain an array of names

 $ jtl -e "name" people.json
[ "Jasmine Daugherty", "Boyd Atkinson", "Petty Shelton", "Byrd Hebert", "Parks Berg", "Teri Stevenson", "Dorothea Munoz" ]

get a collation of specific attributes

  $ jtl -e "{name:name,id:id}" people.json
 {
    "name": [ "Jasmine Daugherty", "Boyd Atkinson", "Petty Shelton", "Byrd Hebert", "Parks Berg", "Teri Stevenson", "Dorothea Munoz" ],
    "id": [ "558a0750ed9439f04ce78be3", "558a0750dc8657c510cc05e1", "558a075036f23b391dad96db", "558a0750960cdff814f14bb9", "558a0750dee279e5ca3ed92c", "558a0750f34b44ee5754a2bd", "558a0750a941ec9ba32b8ff9" ]
 }

get a subset of attributes in separate objects

  $ jtl -e "*/{name:name,id:id}" people.json
[{
   "name": "Jasmine Daugherty",
   "id": "558a0750ed9439f04ce78be3"
}, {
   "name": "Boyd Atkinson",
   "id": "558a0750dc8657c510cc05e1"
}, {
   "name": "Petty Shelton",
   "id": "558a075036f23b391dad96db"
}, {
   "name": "Byrd Hebert",
   "id": "558a0750960cdff814f14bb9"
}, {
   "name": "Parks Berg",
   "id": "558a0750dee279e5ca3ed92c"
}, {
   "name": "Teri Stevenson",
   "id": "558a0750f34b44ee5754a2bd"
}, {
   "name": "Dorothea Munoz",
   "id": "558a0750a941ec9ba32b8ff9"
}]

simple grouping

$ jtl -e "group(element)" people.json
{
   "fire": [{
      "name": "Jasmine Daugherty",
      "id": "558a0750ed9439f04ce78be3",
      "eyeColor": "green",
      "element": "fire"
   }, {
      "name": "Byrd Hebert",
      "id": "558a0750960cdff814f14bb9",
      "eyeColor": "green",
      "element": "fire"
   }],
   "ice": [{
      "name": "Boyd Atkinson",
      "id": "558a0750dc8657c510cc05e1",
      "eyeColor": "brown",
      "element": "ice"
   }, {
      "name": "Parks Berg",
      "id": "558a0750dee279e5ca3ed92c",
      "eyeColor": "green",
      "element": "ice"
   }, {
      "name": "Dorothea Munoz",
      "id": "558a0750a941ec9ba32b8ff9",
      "eyeColor": "brown",
      "element": "ice"
   }],
   "candy": [{
      "name": "Petty Shelton",
      "id": "558a075036f23b391dad96db",
      "eyeColor": "blue",
      "element": "candy"
   }, {
      "name": "Teri Stevenson",
      "id": "558a0750f34b44ee5754a2bd",
      "eyeColor": "blue",
      "element": "candy"
   }]
}

map() applies an expression to every value in an object

$ jtl -e "group(element)/map(eyeColor)" people.json
 {
    "fire": [ "green", "green" ],
    "ice": [ "brown", "green", "brown" ],
    "candy": [ "blue", "blue" ]
 }

Clone this wiki locally