JSONPath എന്നത് എന്താണ്?
JSONPath JSON documents-ന് ഒരു query language ആണ്, XML-ന് XPath-ന്റെ JSON equivalent. Stefan Goessner 2007-ൽ propose ചെയ്ത ഒരു short, readable way ആണ് parser ഇല്ലാതെ JSON tree-ൽ ഒരു node point ചെയ്യാൻ. Expression root selector $ ഉൾക്കൊണ്ട് തുടങ്ങി property accessors, array subscripts, wildcards, recursive descent, filter conditions chain ചെയ്ത് nodes pick ചെയ്യുന്നു. 2024-ൽ IETF RFC 9535 publish ചെയ്ത് syntax standardise ചെയ്തു; ഈ tester jsonpath-plus-ൽ run ആകുന്നു.
JSONPath എങ്ങനെ പ്രവർത്തിക്കുന്നു
ഒരു JSONPath expression ഇടത്തു നിന്ന് വലത്തോട്ട് JSON document-ഇനെ ഒരു step വീതം walk ചെയ്യുന്നു. ഓരോ step-ഉം previous step survive ചെയ്ത nodes-ഇനെ കൂടുതൽ narrow ചെയ്യുന്നു. Full evaluation pipeline:
- Root selector
$ഉൾക്കൊണ്ട് anchor ചെയ്യൽ. ഓരോ expression-ഉം ഇവിടെ തുടങ്ങുന്നു, top-level value ആണ് object-ഉം array-ഉം. Leading$ഇല്ലാത്ത bare property names valid JSONPath അല്ല. - Dot notation (
$.store.book) അല്ലെങ്കിൽ bracket notation ($['store']['book']) ഉൾക്കൊണ്ട് child members-ലേക്ക് walk ചെയ്യൽ. Key-ൽ space, hyphen, valid identifier character അല്ലാത്തത് ഉണ്ടെങ്കിൽ bracket notation mandatory. - Recursive descent operator
..ഉൾക്കൊണ്ട് ഒരേ സമയം ഓരോ level-ഉം search ചെയ്യൽ.$..authortree-ൽ depth ഏതുമാകട്ടെ ഓരോauthorvalue-ഉം collect ചെയ്യുന്നു. - Array elements index ഉൾക്കൊണ്ട് (
[0],[-1]),[start:end]ഉൾക്കൊണ്ട് slice ചെയ്ത്, wildcard[*]ഉൾക്കൊണ്ട് ഓരോ element-ഉം grab ചെയ്യൽ. [?(...)]-ൽ predicate ഉൾക്കൊണ്ട് elements filter ചെയ്യൽ. Predicate-ൽ@current element refer ചെയ്യുന്നു,[?(@.price<10)]price10-ൽ കുറഞ്ഞ items മാത്രം keep ചെയ്യുന്നു.- Output format തിരഞ്ഞെടുക്കൽ. Values matched data return ചെയ്യുന്നു. Paths ഓരോ match-ന്റെ JSONPath return ചെയ്യുന്നു. Pointers ഓരോ match-ന് equivalent RFC 6901 JSON Pointer return ചെയ്യുന്നു.
ഈ JSONPath tester ഉപയോഗിക്കേണ്ടത് എന്തുകൊണ്ട്?
- JSON ബ്രൗസർ വിടുന്നില്ല. Query page-ൽ run ആകുന്നു, production fixtures, customer PII, pre-release API responses machine-ൽ നിൽക്കുന്നു.
- Engine
jsonpath-plus9.x ആണ്, production test suites, CI assertions back ചെയ്യുന്ന library. ഇവിടെ കാണുന്ന results build pipeline-ൽ കാണുന്ന results. - മൂന്ന് output modes: raw Values copy-paste-ന്, Paths engine resolution debug-ന്, RFC 6901 Pointers JSON Patch, JSON Schema workflows-ന്.
- Filter expressions
preventEval: trueഉൾക്കൊണ്ട് run ചെയ്യുന്നു, paste ചെയ്ത query host page-ൽ arbitrary JavaScript execute ചെയ്യില്ല. Slack message, Jira ticket, colleague clipboard-ൽ നിന്ന് expression വരുമ്പോൾ ഇത് important.
JSONPath-ന്റെ സാധാരണ ഉപയോഗങ്ങൾ
Code-ന് JSON payload-ൽ നിന്ന് ഒരു field pull ചെയ്യേണ്ടിടത്ത് recursive descent hand ഉൾക്കൊണ്ടെഴുതാതെ JSONPath ഉണ്ടാകും:
- Postman tests: Postman-ന്റെ Tests tab
pm.response.json()JSONPath-style access ഉൾക്കൊണ്ട് assertions-ന് expose ചെയ്യുന്നു.$.data.user.emailഉൾക്കൊണ്ട് response field pull ചെയ്ത് CI-ൽ assert ചെയ്യൽ. - k6 load tests: k6 scripts
check()block-ൽjsonpath()call ചെയ്ത് response bodies-ൽ നിന്ന് values extract ചെയ്ത് SLA thresholds assert ചെയ്യുന്നു. - JSON DSL for data transforms: AWS Step Functions JSONPath
InputPath,ResultPath,Parameters-ൽ evaluate ചെയ്ത് event payloads reshape ചെയ്യുന്നു. Kuberneteskubectl -o jsonpathcluster objects-ൽ നിന്ന് fields extract ചെയ്യുന്നു.
ഒരു ഉദാഹരണം
Canonical Goessner fixture four books ഉൾക്കൊള്ളുന്ന book store document ആണ്, ഓരോ book-ഉം category, author, title, price carry ചെയ്യുന്നു. Expression $.store.book[?(@.price<10)].title മൂന്ന് steps-ൽ run ആകുന്നു. $.store.book നാലു books-ന്റെ array-ലേക്ക് resolve ചെയ്യുന്നു. Filter [?(@.price<10)] 10-ൽ താഴെ price ഉൾക്കൊള്ളുന്ന ഒരൊറ്റ book keep ചെയ്യുന്നു. .title ആ book-ന്റെ title extract ചെയ്യുന്നു. Result ["Sayings of the Century"]. Paths ["$['store']['book'][0]['title']"], Pointers ["/store/book/0/title"].
Expressions ഇവിടെ prototype ചെയ്ത് Postman, k6, kubectl, Step Functions state machine-ലേക്ക് നേരിട്ട് drop ചെയ്തോളൂ. Paste, query, copy. Network cross ആകില്ല.
JSONPath എന്നത് എന്താണ്?
JSONPath JSON documents-ന് ഒരു query language ആണ്, XML-ന് XPath-ന് analogous. Stefan Goessner 2007-ൽ propose ചെയ്ത്, IETF 2024-ൽ RFC 9535 ആക്കി standardise ചെയ്തു.
$ (document root) ഉൾക്കൊണ്ട് തുടങ്ങുന്ന compact expression syntax ഉൾക്കൊണ്ട് dot notation, array subscripts, wildcards, slices, recursive descent (..), filter expressions ([?(...)]) JSON tree-ൽ nodes select ചെയ്യുന്നു.
JSONPath JMESPath-ൽ നിന്നോ jq-ൽ നിന്നോ എങ്ങനെ വ്യത്യാസം?
മൂന്നും JSON query ചെയ്യുന്നു, grammar, goals വ്യത്യസ്തം. JMESPath AWS CLI / SDK standard: JSONPath-ൽ നിന്ന് stricter, recursive descent ഇല്ല, predictable side-effect-free projection-ന്.
jq Turing-complete scripting language, query, transform, reduce, stream ചെയ്യുന്നു. JSONPath ഇടയ്ക്ക്: recursive descent, filters ഉൾക്കൊണ്ട് JMESPath-ൽ നിന്ന് expressive, jq-ൽ നിന്ന് lighter, general-purpose test tooling-ൽ ഏറ്റവും widely supported.
ഈ tester ഏത് dialect ഉപയോഗിക്കുന്നു?
ഈ tester jsonpath-plus 9.x run ചെയ്യുന്നു. ആ library Goessner 2007 spec implement ചെയ്ത്, RFC 9535-ന്റെ majority cover ചെയ്ത്, type checks (@.string(), @.number(), @.boolean()), parent navigation (^) extension operators add ചെയ്തു.
preventEval: true flag always set ആണ്, filter predicates JavaScript eval() built-in-ന് പകരം safe interpreter run ചെയ്യുന്നു.
Individual matched values copy ചെയ്യാൻ കഴിയുമോ?
അതെ. Copy to clipboard ബട്ടൺ full result block JSON array ആക്കി copy ചെയ്യുന്നു. ഒരൊറ്റ value grab ചെയ്യാൻ output mode Values-ലേക്ക് switch ചെയ്ത്, result textarea-ൽ line select ചെയ്ത് browser normal copy shortcut (Ctrl/Cmd + C) ഉപയോഗിക്കുക.
Output plain JSON text ആണ്, code editor, terminal, Postman test, Slack message-ൽ cleanly paste ചെയ്യാം.