JSONPath क्या है?
JSONPath JSON documents के लिए एक query language है, XML के लिए XPath का JSON equivalent। Stefan Goessner ने 2007 में इसे JSON tree के अंदर एक node को parser लिखे बिना point करने के छोटे, readable तरीके के रूप में प्रस्तावित किया। एक expression root selector $ से शुरू होता है और property accessors, array subscripts, wildcards, recursive descent और filter conditions chain करता है जब तक वे nodes नहीं मिलते जो आप चाहते हैं। 2024 में IETF ने RFC 9535 publish करके उस syntax को standardise किया जो implementations में fragment हो गई थी; यह tester jsonpath-plus पर चलता है, एक widely used JavaScript implementation जो Goessner draft, अधिकतर RFC 9535 और कुछ extension operators cover करती है।
JSONPath कैसे काम करता है
एक JSONPath expression left to right पढ़ता है और JSON document को एक बार में एक step walk करता है। हर step उन nodes का set लेता है जो previous step के बाद बचे और उन्हें और narrow करता है। पूरी evaluation pipeline:
- Root selector
$से anchor करें। हर expression यहाँ start होता है, top-level value पर point करते हुए, चाहे वह object हो या array। Leading$के बिना bare property names valid JSONPath नहीं हैं। - Dot notation (
$.store.book) या bracket notation ($['store']['book']) से child members में walk करें। जब key में space, hyphen या कोई ऐसा character हो जो valid identifier नहीं है तो bracket notation ज़रूरी है। - Recursive descent operator
..से एक साथ हर level search करें। Expression$..authortree में कहीं भी हरauthorvalue collect करता है, depth की परवाह किए बिना। यह वह operator है जो JMESPath में नहीं है। - Array elements को index से pick करें (
[0], jsonpath-plus में last item के लिए[-1]),[start:end]notation से slice करें ([0:3]पहले तीन return करता है), या wildcard[*]से हर element grab करें। - Elements को
[?(...)]के अंदर predicate से filter करें। Predicate के अंदर,@current element refer करता है, इसलिए[?(@.price<10)]केवल उन items रखता है जिनकाpricefield 10 से कम है। Filters path के बाकी हिस्से के साथ compose होते हैं, इसलिए आप filter then descend, या descend then filter कर सकते हैं। - Output format चुनें। Values matched data ही return करता है। Paths हर match का JSONPath return करता है ताकि देख सकें engine ने क्या resolve किया। Pointers हर match के लिए equivalent RFC 6901 JSON Pointer return करता है, तब useful जब downstream consumer JSON Patch या JSON Schema validator हो।
यह JSONPath tester क्यों use करें?
- आपका JSON browser से बाहर नहीं जाता। Query page के अंदर चलती है, इसलिए production fixtures, customer PII और pre-release API responses आपकी machine पर रहते हैं।
- Engine
jsonpath-plus9.x है, वही library जो कई production test suites और CI assertions back करती है। आप यहाँ जो results देखते हैं वे आपकी build pipeline के results से match करते हैं। - तीन output modes common downstream consumers cover करते हैं: copy-paste के लिए raw Values, engine's resolution debug करने के लिए Paths, और JSON Patch और JSON Schema workflows के लिए RFC 6901 Pointers।
- Filter expressions
preventEval: trueके साथ चलते हैं, इसलिए pasted query host page के against arbitrary JavaScript execute नहीं कर सकती। यह important है जब expression Slack message, Jira ticket या colleague के clipboard से आई हो।
JSONPath के सामान्य अनुप्रयोग
JSONPath जहाँ भी code को JSON payload से बिना recursive descent लिखे field निकालना हो वहाँ दिखता है:
- Postman tests: Postman का Tests tab
pm.response.json()JSONPath-style access के साथ assertions के लिए expose करता है। Teams CI में response से field निकालने और उस पर assert करने के लिए$.data.user.emailजैसा single expression लिखती हैं। - k6 load tests: k6 scripts response bodies से values extract करने और SLA thresholds assert करने के लिए
check()block के अंदरjsonpath()call करती हैं। वही expression जो Postman में contract prove करता था, k6 under load test gate कर सकता है। - Data transforms के लिए JSON DSL: AWS Step Functions states के बीच event payloads reshape करने के लिए
InputPath,ResultPathऔरParametersमें JSONPath evaluate करती है। Argo Workflows tasks को array पर fan-out करने के लिएwithParamमें JSONPath use करता है। Kuberneteskubectl -o jsonpathcluster objects से fields extract करने के लिए same syntax use करता है।
Worked example
Canonical Goessner fixture book store document है जिसमें चार books हैं, हर एक में category, author, title और price हैं। उस fixture के against, expression $.store.book[?(@.price<10)].title तीन steps में चलता है। पहले, $.store.book सभी चार books के array को resolve करता है। फिर, filter [?(@.price<10)] केवल 10 से कम price वाली book (8.95 पर entry) रखता है। आखिर में, .title उस book का title extract करता है। Result है ["Sayings of the Century"]। Paths पर switch करने से ["$['store']['book'][0]['title']"] मिलता है, और Pointers से ["/store/book/0/title"]।
अपने expressions यहाँ prototype करें, फिर उन्हें सीधे Postman, k6, kubectl, या Step Functions state machine में डालें। Paste, query, copy। Network से कुछ नहीं गुज़रता।
JSONPath क्या है?
JSONPath JSON documents के लिए एक query language है, XML के लिए XPath के analogous। Stefan Goessner ने 2007 में propose किया और IETF ने 2024 में RFC 9535 के रूप में standardise किया, यह एक compact expression syntax use करता है जो $ (document root) से शुरू होता है और JSON tree के अंदर nodes select करने के लिए dot notation, array subscripts, wildcards, slices, recursive descent (..) और filter expressions ([?(...)]) support करता है।
JSONPath JMESPath या jq से कैसे अलग है?
तीनों JSON query करते हैं, लेकिन उनके grammars और goals अलग हैं। JMESPath AWS CLI / SDK standard है: JSONPath से stricter, recursive descent नहीं, predictable side-effect-free projection के लिए बना। jq एक Turing-complete scripting language है जो JSON query ही नहीं करती बल्कि transform, reduce और stream भी करती है। JSONPath उनके बीच है: recursive descent और filters की वजह से JMESPath से more expressive, jq से lighter, और general-purpose test tooling (Postman, Playwright, REST Assured, kubectl, Step Functions) में सबसे widely supported syntax। यह tester JSONPath implement करता है।
यह tester कौन सा dialect use करता है?
यह tester jsonpath-plus 9.x चलाता है। वह library Goessner 2007 spec implement करती है, अधिकतर RFC 9535 cover करती है, और extension operators जैसे type checks (@.string(), @.number(), @.boolean()) और parent navigation (^) जोड़ती है। preventEval: true flag हमेशा set है, इसलिए filter predicates JavaScript eval() built-in की बजाय safe interpreter के through चलते हैं। कोई pasted query इस page के against arbitrary code execute नहीं कर सकती।
क्या मैं individual matched values copy कर सकता हूँ?
हाँ। Copy to clipboard button पूरे result block को JSON array के रूप में copy करता है। एक single value grab करने के लिए, output mode को Values पर switch करें, फिर result textarea में जो line चाहिए वह select करें और browser का normal copy shortcut (Ctrl/Cmd + C) use करें। Output plain JSON text है, इसलिए code editor, terminal, Postman test या Slack message में cleanly paste होता है।