Skip to content
gurl extract

gurl extract

Test extraction rules against a sample response. No request is sent.

Synopsis

gurl extract [flags] VAR=METHOD:EXPR [VAR=METHOD:EXPR...]

gurl extract reads a response body from --file or stdin and prints what each rule extracts. Use it to get a rule right before saving it on a request with gurl save --extract or gurl edit --extract.

Rules have the form VAR=METHOD:EXPR:

MethodExpressionExample
jsonpathJSONPath, including array indexesorderId=jsonpath:$.data.items[0].id
jqAlias of jsonpathid=jq:$.id
headerResponse header name (pass headers with -H)loc=header:Location
regexRegular expression; the first capture group is the valuen=regex:"amount":(\d+)

JSONPath extraction keeps large numbers exact (1000000, not 1e+06).

Flags

FlagShortDefaultDescription
--file-fstdinResponse body file
--header-HnoneResponse header 'Key: Value' for header rules (repeatable)

Examples

JSONPath from stdin

echo '{"data":{"id":"ord_1"}}' | gurl extract 'orderId=jsonpath:$.data.id'
orderId = ord_1

Several rules against a file

gurl extract -f resp.json -H 'Location: /orders/9' \
  'loc=header:Location' \
  'first=jsonpath:$.data.items[0].id' \
  'n=regex:"amount":(\d+)'

Save the rule once it works

gurl edit "create-order" --extract 'orderId=jsonpath:$.data.id'

Related commands

  • gurl save - Save a request with --extract rules
  • gurl edit - Add or replace extraction rules
  • gurl run - Extracted values and --persist