{"id":13968,"date":"2024-12-16T12:31:40","date_gmt":"2024-12-16T03:31:40","guid":{"rendered":"https:\/\/www.sambuichi.jp\/?p=13968"},"modified":"2024-12-17T12:27:20","modified_gmt":"2024-12-17T03:27:20","slug":"jsonpath%e3%81%a8python%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99","status":"publish","type":"post","link":"https:\/\/www.sambuichi.jp\/?p=13968","title":{"rendered":"JSONPath\u3068Python\u74b0\u5883\u6e96\u5099"},"content":{"rendered":"<p>Views: 25<\/p><div id=\"header\">\n<h1>JSONPath\u3068Python\u74b0\u5883\u6e96\u5099<\/h1>\n<\/div>\n<div id=\"content\">\n<div id=\"preamble\">\n<div class=\"sectionbody\">\n<div class=\"quoteblock abstract\">\n<blockquote><p>\n                    JSONPath\u306f\u3001JSON\u30c7\u30fc\u30bf\u3092\u691c\u7d22\u304a\u3088\u3073\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3059\u308b\u305f\u3081\u306e\u30af\u30a8\u30ea\u8a00\u8a9e\u3067\u3059\u3002JSON Pointer\u3084XPath\u306b\u89e6\u767a\u3055\u308c\u3001\u7279\u306bJSON\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u67d4\u8edf\u306a\u64cd\u4f5c\u3092\u76ee\u7684\u3068\u3057\u3066\u8a2d\u8a08\u3055\u308c\u307e\u3057\u305f\u3002\n                <\/p><\/blockquote><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect1\">\n<h2 id=\"_jsonpath\u306e\u6a19\u6e96\u5316rfc_9535\">1. JSONPath\u306e\u6a19\u6e96\u5316\uff1aRFC 9535<\/h2>\n<div class=\"sectionbody\">\n<div class=\"quoteblock\">\n<blockquote>\n<div class=\"paragraph\">\n<p>1.2. History (\u6b74\u53f2)<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>This document is based on Stefan G\u00f6ssner&#8217;s popular JSONPath proposal (dated 2007-02-21)<br \/>\n                            [JSONPath-orig], builds on the experience from the widespread deployment of its<br \/>\n                            implementations, and provides a normative specification for it.<br \/>\n                            \u672c\u6587\u66f8\u306f\u3001Stefan G\u00f6ssner\u306b\u3088\u308b\u8457\u540d\u306aJSONPath\u63d0\u6848(2007-02-21\u4ed8\u3051)<br \/>\n                            [JSONPath-orig]\u3092\u30d9\u30fc\u30b9\u3068\u3057\u3001\u305d\u306e\u5b9f\u88c5\u304c\u5e83\u304f\u666e\u53ca\u3057\u3066\u304d\u305f\u7d4c\u9a13\u306b\u57fa\u3065\u304d\u3001\u898f\u7bc4\u3068\u306a\u308b\u4ed5\u69d8\u3092\u63d0\u4f9b\u3059\u308b\u3082\u306e\u3067\u3042\u308b\u3002<\/p>\n<\/p><\/div>\n<\/blockquote>\n<div class=\"attribution\">\n                    &#8212; RFC 9535<br \/>\n                    <cite>1.2. History<\/cite>\n                <\/div>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>\u8a73\u7d30\u306a\u60c5\u5831\u306f\u3001\u4ee5\u4e0b\u306e\u516c\u5f0f\u30da\u30fc\u30b8\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\uff1a<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p><a href=\"https:\/\/datatracker.ietf.org\/doc\/rfc9535\/\">https:\/\/datatracker.ietf.org\/doc\/rfc9535\/<\/a><\/p>\n<\/p><\/div>\n<div class=\"imageblock\">\n<div class=\"content\"><a href=\"https:\/\/www.rfc-editor.org\/info\/rfc953\"><br \/>\n                    <img decoding=\"async\" src=\"https:\/\/www.sambuichi.jp\/wp-content\/uploads\/2024\/12\/RFC9535.png\" alt=\"RFC9535\"><\/a>\n                <\/div>\n<\/p><\/div>\n<div class=\"imageblock\">\n<div class=\"content\"><a href=\"https:\/\/datatracker.ietf.org\/doc\/rfc9535\/\"><br \/>\n                    <img decoding=\"async\" src=\"https:\/\/www.sambuichi.jp\/wp-content\/uploads\/2024\/12\/RFC9535History.png\" alt=\"RFC9535History\"><\/a>\n                <\/div>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>RFC 9535\u306f\u3001JSONPath\u306e\u6a19\u6e96\u5316\u3092\u76ee\u7684\u3068\u3057\u305f\u516c\u5f0f\u306a\u6587\u66f8\u3067\u3042\u308a\u3001IETF\u306b\u3088\u3063\u30662024\u5e74\u306b\u7b56\u5b9a\u3055\u308c\u307e\u3057\u305f\u3002JSON\u30c7\u30fc\u30bf\u306b\u5bfe\u3059\u308b\u8907\u96d1\u306a\u30af\u30a8\u30ea\u64cd\u4f5c\u3092\u7c21\u6f54\u306b\u8868\u73fe\u3059\u308b\u305f\u3081\u306e\u8868\u8a18\u6cd5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\n                <\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>\u3053\u306e\u4ed5\u69d8\u306f\u3001\u904e\u53bb\u306eDraft\u4ed5\u69d8(<a href=\"https:\/\/datatracker.ietf.org\/doc\/draft-ietf-jsonpath-base\/history\/\" rel=\"noopener\" target=\"_blank\">draft-ietf-jsonpath-base-21<\/a>\uff09\u3092\u57fa\u306b\u7b56\u5b9a\u3055\u308c\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u6a5f\u80fd\u3092\u7279\u5fb4\u3068\u3057\u3066\u3044\u307e\u3059\uff1a\n                <\/p>\n<\/p><\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>\u518d\u5e30\u691c\u7d22\uff08\u4f8b\uff1a<code>$..author<\/code>\uff09<\/p>\n<\/li>\n<li>\n<p>\u6761\u4ef6\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\uff08\u4f8b\uff1a<code>[?(@.price &lt; 10)]<\/code>\uff09<\/p>\n<\/li>\n<li>\n<p>\u914d\u5217\u7bc4\u56f2\u6307\u5b9a\uff08\u4f8b\uff1a<code>[:2]<\/code>\uff09<\/p>\n<\/li>\n<\/ul><\/div>\n<div class=\"imageblock\">\n<div class=\"content\"><a href=\"https:\/\/datatracker.ietf.org\/doc\/draft-ietf-jsonpath-base\/history\/\"><br \/>\n                    <img decoding=\"async\" src=\"https:\/\/www.sambuichi.jp\/wp-content\/uploads\/2024\/12\/draft-ietf-jsonpath-base-21.png\" alt=\"draft ietf jsonpath base 21\"><\/a>\n                <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect1\">\n<h2 id=\"_jsonpath\u5f0f\u306e\u6982\u8981\">2. JSONPath\u5f0f\u306e\u6982\u8981<\/h2>\n<div class=\"sectionbody\">\n<div class=\"quoteblock\">\n<blockquote>\n<div class=\"paragraph\">\n<p>1.4. Overview of JSONPath Expressions (JSONPath\u5f0f\u306e\u6982\u8981)<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>A JSONPath expression is applied to a JSON value, known as the query argument. The output is<br \/>\n                            a nodelist.<br \/>\n                            JSONPath \u5f0f\u306f\u3001\u30af\u30a8\u30ea\u30fc\u5f15\u6570\u3068\u3057\u3066\u77e5\u3089\u308c\u308b JSON \u5024\u306b\u9069\u7528\u3055\u308c\u307e\u3059\u3002\u51fa\u529b\u306f\u30ce\u30fc\u30c9\u30ea\u30b9\u30c8\u3067\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>A JSONPath expression consists of an identifier followed by a series of zero or more<br \/>\n                            segments, each of which contains one or more selectors.<br \/>\n                            JSONPath \u5f0f\u306f\u3001\u8b58\u5225\u5b50\u306b\u7d9a\u304f 0 \u500b\u4ee5\u4e0a\u306e\u30bb\u30b0\u30e1\u30f3\u30c8\u3067\u69cb\u6210\u3055\u308c\u3001\u5404\u30bb\u30b0\u30e1\u30f3\u30c8\u306b\u306f 1 \u3064\u4ee5\u4e0a\u306e\u30bb\u30ec\u30af\u30bf\u304c\u542b\u307e\u308c\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>1.4.1. Identifiers (\u8b58\u5225\u5b50)<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>The root node identifier $ refers to the root node of the query argument, i.e., to the<br \/>\n                            argument as a whole.<br \/>\n                            \u30eb\u30fc\u30c8\u30fb\u30ce\u30fc\u30c9\u8b58\u5225\u5b50 $ \u306f\u3001\u30af\u30a8\u30ea\u5f15\u6570\u306e\u30eb\u30fc\u30c8\u30fb\u30ce\u30fc\u30c9\u3001\u3064\u307e\u308a\u5f15\u6570\u5168\u4f53\u3092\u6307\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>The current node identifier @ refers to the current node in the context of the evaluation of<br \/>\n                            a filter expression (Section 2.3.5).<br \/>\n                            \u73fe\u5728\u306e\u30ce\u30fc\u30c9\u8b58\u5225\u5b50 @ \u306f\u3001\u30d5\u30a3\u30eb\u30bf\u5f0f\u306e\u8a55\u4fa1\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u306b\u304a\u3051\u308b\u73fe\u5728\u306e\u30ce\u30fc\u30c9\u3092\u6307\u3057\u307e\u3059 (\u30bb\u30af\u30b7\u30e7\u30f3 2.3.5)\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>1.4.2. Segments (\u30bb\u30b0\u30e1\u30f3\u30c8)<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Segments select children ([&lt;selectors&gt;]) or descendants (..\u2060[&lt;selectors&gt;]) of an<br \/>\n                            input value.<br \/>\n                            \u30bb\u30b0\u30e1\u30f3\u30c8\u306f\u5165\u529b\u5024\u306e\u5b50 ([&lt;selectors&gt;]) \u307e\u305f\u306f\u5b50\u5b6b (.[&lt;selectors&gt;]) \u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Segments can use bracket notation, for example:<br \/>\n                            \u30bb\u30b0\u30e1\u30f3\u30c8\u306b\u306f\u62ec\u5f27\u3092\u4f7f\u7528\u3057\u307e\u3059\uff1a<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>$[&#8216;store&#8217;][&#8216;book&#8217;][0][&#8216;title&#8217;]<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>or the more compact dot notation, for example:<br \/>\n                            \u3042\u308b\u3044\u306f\u3001\u3088\u308a\u30b3\u30f3\u30d1\u30af\u30c8\u306a\u30c9\u30c3\u30c8\u8a18\u6cd5\u3082\u4f7f\u7528\u3067\u304d\u307e\u3059\uff1a<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>$.store.book[0].title<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Bracket notation contains one or more (comma-separated) selectors of any kind. Selectors are<br \/>\n                            detailed in the next section.<br \/>\n                            \u30d6\u30e9\u30b1\u30c3\u30c8\u8a18\u6cd5\u306f\u30011\u3064\u4ee5\u4e0a\u306e\uff08\u30ab\u30f3\u30de\u3067\u533a\u5207\u3089\u308c\u305f\uff09\u4efb\u610f\u306e\u7a2e\u985e\u306e\u30bb\u30ec\u30af\u30bf\u3092\u542b\u307f\u307e\u3059\u3002\u30bb\u30ec\u30af\u30bf\u306b\u3064\u3044\u3066\u306f\u3001\u6b21\u306e\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u8a73\u3057\u304f\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>A JSONPath expression may use a combination of bracket and dot notations.<br \/>\n                            JSONPath\u5f0f\u3067\u306f\u3001\u30d6\u30e9\u30b1\u30c3\u30c8\u8868\u8a18\u3068\u30c9\u30c3\u30c8\u8868\u8a18\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u7528\u3067\u304d\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>This document treats the bracket notations as canonical and defines the shorthand dot<br \/>\n                            notation in terms of bracket notation. Examples and descriptions use shorthand where<br \/>\n                            convenient.<br \/>\n                            \u3053\u306e\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u306f\u3001\u30d6\u30e9\u30b1\u30c3\u30c8\u8868\u8a18\u3092\u6a19\u6e96\u7684\u306a\u3082\u306e\u3068\u3057\u3066\u6271\u3044\u3001\u30d6\u30e9\u30b1\u30c3\u30c8\u8868\u8a18\u306e\u89b3\u70b9\u304b\u3089\u7701\u7565\u8a18\u6cd5\u306e\u30c9\u30c3\u30c8\u8868\u8a18\u3092\u5b9a\u7fa9\u3059\u308b\u3002\u4f8b\u3084\u8aac\u660e\u3067\u306f\u3001\u4fbf\u5229\u306a\u5834\u5408\u306b\u306f\u7701\u7565\u8a18\u6cd5\u3092\u4f7f\u7528\u3059\u308b\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>1.4.3. Selectors (\u30bb\u30ec\u30af\u30bf)<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>A name selector, e.g., &#8216;name&#8217;, selects a named child of an object.<br \/>\n                            \u540d\u524d\u30bb\u30ec\u30af\u30bf\u3001\u4f8b\u3048\u3070&#8217;name&#8217;\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u540d\u524d\u4ed8\u304d\u306e\u5b50\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>An index selector, e.g., 3, selects an indexed child of an array.<br \/>\n                            \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30fb\u30bb\u30ec\u30af\u30bf\u3001\u4f8b\u3048\u30703\u306f\u3001\u914d\u5217\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u4ed8\u304d\u306e\u5b50\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>In the expression [*], a wildcard * (Section 2.3.2) selects all children of a node, and in<br \/>\n                            the expression ..[*], it selects all descendants of a node.<br \/>\n                            \u5f0f[*]\u3067\u306f\u3001\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9*\uff08\u30bb\u30af\u30b7\u30e7\u30f32.3.2\uff09\u306f\u30ce\u30fc\u30c9\u306e\u3059\u3079\u3066\u306e\u5b50\u3092\u9078\u629e\u3057\u3001\u5f0f ..[*]\u3067\u306f\u30ce\u30fc\u30c9\u306e\u3059\u3079\u3066\u306e\u5b50\u5b6b\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>An array slice start:end:step (Section 2.3.4) selects a series of elements from an array,<br \/>\n                            giving a start position, an end position, and an optional step value that moves the position<br \/>\n                            from the start to the end.<br \/>\n                            \u914d\u5217\u30b9\u30e9\u30a4\u30b9 start:end:step<br \/>\n                            (\u30bb\u30af\u30b7\u30e7\u30f32.3.4)\u306f\u3001\u914d\u5217\u304b\u3089\u4e00\u9023\u306e\u8981\u7d20\u3092\u9078\u629e\u3057\u3001\u958b\u59cb\u4f4d\u7f6e\u3001\u7d42\u4e86\u4f4d\u7f6e\u3001\u304a\u3088\u3073\u958b\u59cb\u4f4d\u7f6e\u304b\u3089\u7d42\u4e86\u4f4d\u7f6e\u3078\u79fb\u52d5\u3059\u308b\u30aa\u30d7\u30b7\u30e7\u30f3\u306e\u30b9\u30c6\u30c3\u30d7\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>A filter expression ?&lt;logical-expr&gt; selects certain children of an object or array, as<br \/>\n                            in:<br \/>\n                            \u30d5\u30a3\u30eb\u30bf\u5f0f ?&lt;logical-expr&gt; \u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3084\u914d\u5217\u306e\u7279\u5b9a\u306e\u5b50\u8981\u7d20\u3092\u9078\u629e\u3057\u307e\u3059\uff1a<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>$.store.book[?@.price &lt; 10].title<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>1.4.4. Summary (\u6982\u8981)<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Table 1 provides a brief overview of JSONPath syntax.<br \/>\n                            \u8868 1 \u306b\u3001JSONPath \u69cb\u6587\u306e\u6982\u8981\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Table 1: Overview of JSONPath Syntax (JSONPath\u69cb\u6587\u306e\u6982\u8981)<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Table 1: Overview of JSONPath Syntax<\/p>\n<\/p><\/div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<colgroup>\n<col style=\"width: 20%;\">\n<col style=\"width: 40%;\">\n<col style=\"width: 40%;\">\n                        <\/colgroup>\n<thead>\n<tr>\n<th class=\"tableblock halign-center valign-top\">Syntax Element (\u69cb\u6587\u8981\u7d20)<\/th>\n<th class=\"tableblock halign-center valign-top\">Description<\/th>\n<th class=\"tableblock halign-center valign-top\">\u8aac\u660e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">root node identifier (Section 2.2)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u30eb\u30fc\u30c8\u30fb\u30ce\u30fc\u30c9\u8b58\u5225\u5b50 (\u30bb\u30af\u30b7\u30e7\u30f3 2.2)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">@<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">current node identifier (Section 2.3.5) (valid only within<br \/>\n                                        filter selectors)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u73fe\u5728\u306e\u30ce\u30fc\u30c9\u8b58\u5225\u5b50 (\u30bb\u30af\u30b7\u30e7\u30f3 2.3.5) (\u30d5\u30a3\u30eb\u30bf\u30bb\u30ec\u30af\u30bf\u5185\u3067\u306e\u307f\u6709\u52b9)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">[&lt;selectors&gt;]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">child segment (Section 2.5.1): selects zero or more children<br \/>\n                                        of a node<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u5b50\u30bb\u30b0\u30e1\u30f3\u30c8 (\u30bb\u30af\u30b7\u30e7\u30f32.5.1): \u30ce\u30fc\u30c9\u306e0\u500b\u4ee5\u4e0a\u306e\u5b50\u3092\u9078\u629e\u3059\u308b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">.name<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">shorthand for [&#8216;name&#8217;]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">[&#8216;name&#8217;] \u306e\u7701\u7565\u8a18\u6cd5<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">.*<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">shorthand for [*]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">[*]\u306e\u7701\u7565\u5f62<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">..\u2060[&lt;selectors&gt;]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">descendant segment (Section 2.5.2): selects zero or more<br \/>\n                                        descendants of a node<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u5b50\u5b6b\u30bb\u30b0\u30e1\u30f3\u30c8 (\u30bb\u30af\u30b7\u30e7\u30f3 2.5.2): \u30ce\u30fc\u30c9\u306e\u30bc\u30ed\u500b\u4ee5\u4e0a\u306e\u5b50\u5b6b\u3092\u9078\u629e\u3059\u308b\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">..name<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">shorthand for ..[&#8216;name&#8217;]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">..[&#8216;name&#8217;] \u306e\u7701\u7565\u8a18\u6cd5<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">..*<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">shorthand for ..[*]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">..[*] \u306e\u7701\u7565\u8a18\u6cd5<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">&#8216;name&#8217;<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">name selector (Section 2.3.1): selects a named child of an<br \/>\n                                        object<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u540d\u524d\u30bb\u30ec\u30af\u30bf\uff08\u30bb\u30af\u30b7\u30e7\u30f32.3.1\uff09\uff1a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u540d\u524d\u4ed8\u304d\u5b50\u3092\u9078\u629e\u3059\u308b<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">*<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">wildcard selector (Section 2.3.2): selects all children of a<br \/>\n                                        node<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u30ef\u30a4\u30eb\u30c9\u30ab\u30fc\u30c9\u30bb\u30ec\u30af\u30bf (\u30bb\u30af\u30b7\u30e7\u30f3 2.3.2): \u30ce\u30fc\u30c9\u306e\u3059\u3079\u3066\u306e\u5b50\u3092\u9078\u629e\u3057\u307e\u3059\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">3<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">index selector (Section 2.3.3): selects an indexed child of an<br \/>\n                                        array (from 0)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30bb\u30ec\u30af\u30bf\uff08\u30bb\u30af\u30b7\u30e7\u30f3 2.3.3\uff09\uff1a\u914d\u5217\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u4ed8\u304d\u306e\u5b50\uff080 \u304b\u3089\uff09\u3092\u9078\u629e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">0:100:5<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">array slice selector (Section 2.3.4): start:end:step for<br \/>\n                                        arrays<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u914d\u5217\u30b9\u30e9\u30a4\u30b9\u30bb\u30ec\u30af\u30bf\uff08\u30bb\u30af\u30b7\u30e7\u30f32.3.4\uff09\uff1a\u914d\u5217\u306e\u958b\u59cb:\u7d42\u4e86:\u30b9\u30c6\u30c3\u30d7<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">?&lt;logical-expr&gt;<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">filter selector (Section 2.3.5): selects particular children<br \/>\n                                        using a logical expression<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u30d5\u30a3\u30eb\u30bf\u30bb\u30ec\u30af\u30bf (\u7b2c2.3.5\u7bc0): \u8ad6\u7406\u5f0f\u3067\u7279\u5b9a\u306e\u5b50\u3092\u9078\u629e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">length(@.foo)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">function extension (Section 2.4): invokes a function in a<br \/>\n                                        filter expression<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u95a2\u6570\u62e1\u5f35 (\u7b2c2.4\u7bc0): \u30d5\u30a3\u30eb\u30bf\u5f0f\u3067\u95a2\u6570\u3092\u547c\u3073\u51fa\u3059<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"paragraph\">\n<p>www.DeepL.com\/Translator\uff08\u7121\u6599\u7248\uff09\u3067\u7ffb\u8a33\u3057\u307e\u3057\u305f\u3002<\/p>\n<\/p><\/div>\n<\/blockquote>\n<div class=\"attribution\">\n                    &#8212; RFC 9535\n                <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect1\">\n<h2 id=\"_json_pointer\u3068\u306e\u9055\u3044\">3. JSON Pointer\u3068\u306e\u9055\u3044<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>JSON Pointer\uff08<a href=\"https:\/\/triple-underscore.github.io\/RFC6901-ja.html\">RFC<br \/>\n                        6901<\/a>\uff09\u306f\u3001JSON\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u5185\u306e\u7279\u5b9a\u306e\u5024\u3092\u4e00\u610f\u306b\u6307\u3057\u793a\u3059\u30b7\u30f3\u30d7\u30eb\u306a\u69cb\u6587\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u6761\u4ef6\u4ed8\u304d\u306e\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3084\u7bc4\u56f2\u6307\u5b9a\u306a\u3069\u3001\u8907\u96d1\u306a\u64cd\u4f5c\u306b\u306f\u4e0d\u5411\u304d\u3067\u3059\u3002<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect1\">\n<h2 id=\"_xpath\u3068\u306e\u6bd4\u8f03\">4. XPath\u3068\u306e\u6bd4\u8f03<\/h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p><a\n                        href=\"https:\/\/www.w3.org\/TR\/xpath20\/\">XPath<\/a>\u306fXML\u6587\u66f8\u306e\u30af\u30a8\u30ea\u8a00\u8a9e\u3068\u3057\u3066\u5e83\u304f\u5229\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001JSONPath\u306fJSON\u69cb\u9020\u306b\u7279\u5316\u3057\u3066\u3044\u307e\u3059\u3002XPath\u306b\u4f3c\u305f\u69cb\u6587\u8981\u7d20\uff08\u4f8b\uff1a\u518d\u5e30\u691c\u7d22\u3084\u6761\u4ef6\u5f0f\uff09\u304c\u63a1\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u304c\u3001JSON\u30c7\u30fc\u30bf\u306e\u7279\u6027\u306b\u5408\u308f\u305b\u3066\u7c21\u7565\u5316\u3055\u308c\u3066\u3044\u307e\u3059\u3002\n                <\/p>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect1\">\n<h2 id=\"_python\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u9078\u629e\">5. Python\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u9078\u629e<\/h2>\n<div class=\"sectionbody\">\n<div class=\"sect2\">\n<h3 id=\"_\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8abf\u67fb\">5.1. \u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8abf\u67fb<\/h3>\n<div class=\"paragraph\">\n<p>Python\u3067\u306f\u3001JSONPath\u3092\u5b9f\u88c5\u3059\u308b\u3044\u304f\u3064\u304b\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u5b58\u5728\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u4e3b\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8abf\u67fb\u3057\u307e\u3057\u305f\uff1a<\/p>\n<\/p><\/div>\n<div class=\"olist arabic\">\n<ol class=\"arabic\">\n<li>\n<p><strong>jsonpath-ng<\/strong><\/p>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>\u6a19\u6e96\u7684\u306aJSONPath\u69cb\u6587\u3092\u30b5\u30dd\u30fc\u30c8\u3002<\/p>\n<\/li>\n<li>\n<p>\u518d\u5e30\u691c\u7d22\u3084\u5358\u7d14\u306a\u9078\u629e\u306b\u5bfe\u5fdc\u3002<\/p>\n<\/li>\n<li>\n<p>\u6761\u4ef6\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u306b\u306f\u5236\u9650\u304c\u3042\u308b\u305f\u3081\u3001\u62e1\u5f35\u304c\u5fc5\u8981\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/li>\n<li>\n<p><strong>jsonpath-ng.ext<\/strong><\/p>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>jsonpath-ng\u3092\u62e1\u5f35\u3057\u3001\u6761\u4ef6\u9078\u629e\uff08<code>[?@.price &lt; 10]<\/code>\uff09\u306a\u3069\u3092\u30b5\u30dd\u30fc\u30c8\u3002<\/p>\n<\/li>\n<li>\n<p>\u73fe\u5728\u306e\u3068\u3053\u308d\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306b\u5931\u6557\u3059\u308b\u3053\u3068\u304c\u591a\u3044\uff08\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u554f\u984c\uff09\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/li>\n<li>\n<p><strong>jsonpath-python<\/strong><\/p>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>\u4ed6\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u6bd4\u3079\u308b\u3068\u7c21\u6613\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u6a19\u6e96JSONPath\u69cb\u6587\u3092\u30b5\u30dd\u30fc\u30c8\u3002<\/p>\n<\/li>\n<li>\n<p>\u6761\u4ef6\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3084\u7bc4\u56f2\u6307\u5b9a\u306f\u72ec\u81ea\u5b9f\u88c5\u304c\u5fc5\u8981\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/li>\n<\/ol><\/div>\n<\/p><\/div>\n<div class=\"sect2\">\n<h3 id=\"_\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6642\u306e\u554f\u984c\">5.2. \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6642\u306e\u554f\u984c<\/h3>\n<div class=\"paragraph\">\n<p>`jsonpath-ng.ext`\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3092\u8a66\u307f\u305f\u969b\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u306b\u76f4\u9762\u3057\u307e\u3057\u305f\uff1a<\/p>\n<\/p><\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre\r\n                            class=\"highlight\"><code>ERROR: Could not find a version that satisfies the requirement jsonpath-ng.ext<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>\u307e\u305f\u3001`jsonpath-ng`\u3084`jsonpath-python`\u3082\u4e00\u90e8\u306e\u62e1\u5f35\u6a5f\u80fd\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044\u305f\u3081\u3001\u30ab\u30b9\u30bf\u30e0\u5b9f\u88c5\u304c\u5fc5\u8981\u3067\u3057\u305f\u3002<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect2\">\n<h3 id=\"_\u6700\u7d42\u7684\u306a\u9078\u629e\">5.3. \u6700\u7d42\u7684\u306a\u9078\u629e<\/h3>\n<div class=\"paragraph\">\n<p>\u6700\u7d42\u7684\u306b\u3001<strong>jsonpath-ng<\/strong>\u3092\u9078\u629e\u3057\u307e\u3057\u305f\u3002\u7406\u7531\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\uff1a<\/p>\n<\/p><\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>\u6a19\u6e96\u7684\u306aJSONPath\u69cb\u6587\u306e\u30b5\u30dd\u30fc\u30c8\u3002<\/p>\n<\/li>\n<li>\n<p>\u62e1\u5f35\u53ef\u80fd\u306a\u69cb\u9020\u3067\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u304c\u5bb9\u6613\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ed6\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u306b\u6bd4\u3079\u3001Python\u30b3\u30df\u30e5\u30cb\u30c6\u30a3\u5185\u3067\u306e\u4f7f\u7528\u4f8b\u304c\u591a\u3044\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect1\">\n<h2 id=\"_jsonpath\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a73\u7d30\u89e3\u8aac\">6. JSONPath\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a73\u7d30\u89e3\u8aac<\/h2>\n<div class=\"sectionbody\">\n<div class=\"sect2\">\n<h3 id=\"_\u30b5\u30f3\u30d7\u30ebjson\u30c7\u30fc\u30bf\">6.1. \u30b5\u30f3\u30d7\u30ebJSON\u30c7\u30fc\u30bf<\/h3>\n<div class=\"paragraph\">\n<p>\u4ee5\u4e0b\u306eJSON\u30c7\u30fc\u30bf\u3092\u4f7f\u7528\u3057\u3066\u3001JSONPath\u30af\u30a8\u30ea\u3092\u30c6\u30b9\u30c8\u3057\u307e\u3059\u3002\u3053\u306e\u30c7\u30fc\u30bf\u306f\u3001RFC 9535 1.5. JSONPath Examples (JSONPath\u306e\u4f8b)<br \/>\n                        \u3067\u793a\u3055\u308c\u305f\u3082\u306e\u3092\u62e1\u5f35\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>The examples are based on the simple JSON value shown in Figure 1, representing a bookstore<br \/>\n                        (which also has a bicycle).<br \/>\n                        \u3053\u306e\u4f8b\u306f\u3001\u56f31\u306b\u793a\u3059\u30b7\u30f3\u30d7\u30eb\u306aJSON\u5024\u306b\u57fa\u3065\u3044\u3066\u304a\u308a\u3001\u66f8\u5e97\uff08\u81ea\u8ee2\u8eca\u3082\u3042\u308b\uff09\u3092\u8868\u3057\u3066\u3044\u308b\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Figure 1: Example JSON Value<\/p>\n<\/p><\/div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">data = {\r\n    \"store\": {\r\n        \"book\": [\r\n            {\r\n                \"category\": \"reference\",\r\n                \"author\": \"Nigel Rees\",\r\n                \"title\": \"Sayings of the Century\",\r\n                \"price\": 8.95,\r\n            },\r\n            {\r\n                \"category\": \"fiction\",\r\n                \"author\": \"Evelyn Waugh\",\r\n                \"title\": \"Sword of Honour\",\r\n                \"price\": 12.99,\r\n            },\r\n            {\r\n                \"category\": \"fiction\",\r\n                \"author\": \"Herman Melville\",\r\n                \"title\": \"Moby Dick\",\r\n                \"isbn\": \"0-553-21311-3\",\r\n                \"price\": 8.99,\r\n            },\r\n            {\r\n                \"category\": \"fiction\",\r\n                \"author\": \"J. R. R. Tolkien\",\r\n                \"title\": \"The Lord of the Rings\",\r\n                \"isbn\": \"0-395-19395-8\",\r\n                \"price\": 22.99,\r\n            },\r\n        ],\r\n        \"bicycle\": {\"color\": \"red\", \"price\": 399},\r\n    }\r\n}<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Table 2 shows some JSONPath queries that might be applied to this example and their intended<br \/>\n                        results.<br \/>\n                        \u8868 2 \u306b\u3001\u3053\u306e\u4f8b\u306b\u9069\u7528\u3055\u308c\u308b\u53ef\u80fd\u6027\u306e\u3042\u308b JSONPath \u30af\u30a8\u30ea\u30fc\u3068\u3001\u305d\u306e\u610f\u56f3\u3059\u308b\u7d50\u679c\u3092\u793a\u3057\u307e\u3059\u3002<\/p>\n<\/p><\/div>\n<div class=\"paragraph\">\n<p>Table 2: Example JSONPath Expressions and Their Intended Results When Applied to the Example JSON<br \/>\n                        Value<br \/>\n                        \u8868 2: \u4f8b\u306e JSON \u5024\u306b\u9069\u7528\u3055\u308c\u308b JSONPath \u5f0f\u3068\u305d\u306e\u610f\u56f3\u3059\u308b\u7d50\u679c\u306e\u4f8b<\/p>\n<\/p><\/div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<colgroup>\n<col style=\"width: 33.3333%;\">\n<col style=\"width: 33.3333%;\">\n<col style=\"width: 33.3334%;\">\n                    <\/colgroup>\n<thead>\n<tr>\n<th class=\"tableblock halign-left valign-top\">JSONPath<\/th>\n<th class=\"tableblock halign-left valign-top\">Intended Result<\/th>\n<th class=\"tableblock halign-left valign-top\">\u610f\u56f3\u3059\u308b\u7d50\u679c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$.store.book[*].author<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">the authors of all books in the store<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u30b9\u30c8\u30a2\u5185\u306e\u3059\u3079\u3066\u306e\u672c\u306e\u8457\u8005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..author<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">all authors<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u3059\u3079\u3066\u306e\u8457\u8005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$.store.*<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">all things in the store, which are some books and a red bicycle\n                                <\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u30b9\u30c8\u30a2\u306b\u3042\u308b\u3059\u3079\u3066\u306e\u3082\u306e\u3001\u3064\u307e\u308a\u3044\u304f\u3064\u304b\u306e\u672c\u3068\u8d64\u3044\u81ea\u8ee2\u8eca<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$.store..price<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">the prices of everything in the store\uff5c\u5e97\u5185\u306e\u3059\u3079\u3066\u306e\u3082\u306e\u306e\u4fa1\u683c<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[2]<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">the third book<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">3\u518a\u76ee\u306e\u672c<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[2].author<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">the third book&#8217;s author\uff5c3\u518a\u76ee\u306e\u672c\u306e\u8457\u8005<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[2].publisher<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">empty result: the third book does not have a &#8220;publisher&#8221;<br \/>\n                                    member\uff5c\u7a7a\u306e\u7d50\u679c: 3\u518a\u76ee\u306e\u672c\u306b\u306f \u300cpublisher \u300d\u30e1\u30f3\u30d0\u304c\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[-1]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">the last book in order<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u9806\u756a\u306e\u6700\u5f8c\u306e\u672c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[0,1]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">the first two books<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u6700\u521d\u306e2\u518a\u306e\u672c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[:2]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">the first two books<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u6700\u521d\u306e2\u518a\u306e\u672c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[?@.isbn]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">all books with an ISBN number<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">ISBN\u756a\u53f7\u306e\u3042\u308b\u3059\u3079\u3066\u306e\u672c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[?@.price&lt;10]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">all books cheaper than 10<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">10\u3088\u308a\u5b89\u3044\u3059\u3079\u3066\u306e\u672c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..*<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">all member values and array elements contained in the input value\n                                <\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u5165\u529b\u5024\u306b\u542b\u307e\u308c\u308b\u3059\u3079\u3066\u306e\u30e1\u30f3\u30d0\u5024\u3068\u914d\u5217\u8981\u7d20<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"paragraph\">\n<p>Table 2: Example JSONPath Expressions and Their Intended Results When Applied to the Example JSON<br \/>\n                        Value<br \/>\n                        \u88682\uff1aJSONPath\u5f0f\u306e\u4f8b\u3068\u3001JSON\u5024\u306e\u4f8b\u306b\u9069\u7528\u3057\u305f\u5834\u5408\u306e\u610f\u56f3\u3059\u308b\u7d50\u679c<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect2\">\n<h3 id=\"_\u5404\u95a2\u6570\u306e\u8a73\u7d30\u89e3\u8aac\">6.2. \u5404\u95a2\u6570\u306e\u8a73\u7d30\u89e3\u8aac<\/h3>\n<div class=\"sect3\">\n<h4 id=\"_flatten\u95a2\u6570\">6.2.1. flatten\u95a2\u6570<\/h4>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">def flatten(results):\r\n    \"\"\"Flatten nested lists into a single list.\"\"\"\r\n    flat = []\r\n    for item in results:\r\n        if isinstance(item, list):\r\n            flat.extend(flatten(item))\r\n        else:\r\n            flat.append(item)\r\n    return flat<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><strong>\u76ee\u7684<\/strong>: \u5165\u308c\u5b50\u69cb\u9020\u306b\u306a\u3063\u305f\u30ea\u30b9\u30c8\u30921\u6b21\u5143\u306e\u30ea\u30b9\u30c8\u306b\u5909\u63db\u3057\u307e\u3059\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u30dd\u30a4\u30f3\u30c8<\/strong>:<\/p>\n<\/li>\n<li>\n<p>\u518d\u5e30\u7684\u306b\u30ea\u30b9\u30c8\u3092\u5c55\u958b\u3002<\/p>\n<\/li>\n<li>\n<p>JSONPath\u30af\u30a8\u30ea\u306e\u7d50\u679c\u304c\u30cd\u30b9\u30c8\u3057\u3066\u3044\u308b\u5834\u5408\u306b\u4fbf\u5229\u3067\u3059\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<div class=\"sect3\">\n<h4 id=\"_recursive_descent\u95a2\u6570\">6.2.2. recursive_descent\u95a2\u6570<\/h4>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">def recursive_descent(data, key=None, handle_normal=True):\r\n    \"\"\"\r\n    Traverse the JSON structure recursively to find all instances of a given key.\r\n    If no key is provided, collect all elements (for recursive wildcards like $..*).\r\n    \"\"\"\r\n    if handle_normal and key:\r\n        query = f\"$..{key}\" if key != \"*\" else \"$..*\"\r\n        try:\r\n            jsonpath_expr = parse(query)\r\n            result = [match.value for match in jsonpath_expr.find(data)]\r\n            return result\r\n        except Exception:\r\n            pass  # Fallback to explicit handling if JSONPath fails\r\n\r\n    results = []\r\n    if isinstance(data, dict):\r\n        for k, v in data.items():\r\n            if key is None or k == key:\r\n                results.append(v)\r\n            results.extend(recursive_descent(v, key, handle_normal=False))\r\n    elif isinstance(data, list):\r\n        for item in data:\r\n            results.extend(recursive_descent(item, key, handle_normal=False))\r\n    return results<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><strong>\u76ee\u7684<\/strong>: \u518d\u5e30\u7684\u306bJSON\u30c7\u30fc\u30bf\u3092\u63a2\u7d22\u3057\u3066\u6307\u5b9a\u3055\u308c\u305f\u30ad\u30fc\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u7279\u5fb4<\/strong>:<\/p>\n<\/li>\n<li>\n<p><code>$..key<\/code> \u306e\u3088\u3046\u306a\u518d\u5e30\u7684\u30af\u30a8\u30ea\u3092\u30b5\u30dd\u30fc\u30c8\u3002<\/p>\n<\/li>\n<li>\n<p>JSONPath\u306e\u5931\u6557\u6642\u306b\u30d5\u30a9\u30fc\u30eb\u30d0\u30c3\u30af\u51e6\u7406\u3092\u5b9f\u88c5\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<div class=\"sect3\">\n<h4 id=\"_manual_filter\u95a2\u6570\">6.2.3. manual_filter\u95a2\u6570<\/h4>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">def manual_filter(data, condition):\r\n    \"\"\"\r\n    Apply a manual filter condition (e.g., @.price &lt; 10) to a list of items.\r\n    Safely evaluates the condition for dictionary items.\r\n    \"\"\"\r\n    filtered = []\r\n    for item in data:\r\n        if isinstance(item, dict):\r\n            try:\r\n                # Replace @.key with item['key'] dynamically for safe access\r\n                condition_replaced = re.sub(r\"@\\.(\\w+)\", r'item[\"\\1\"]', condition)\r\n                if eval(condition_replaced):\r\n                    filtered.append(item)\r\n            except (KeyError, AttributeError, SyntaxError):\r\n                # Skip items where the condition cannot be applied\r\n                pass\r\n    return filtered<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><strong>\u76ee\u7684<\/strong>: \u6761\u4ef6\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\uff08\u4f8b: <code>[?@.price &lt; 10]<\/code>\uff09\u3092\u5b9f\u73fe\u3057\u307e\u3059\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u70b9<\/strong>:<\/p>\n<\/li>\n<li>\n<p>\u6761\u4ef6\u3092\u5b89\u5168\u306b\u8a55\u4fa1\u3059\u308b\u305f\u3081\u306b\u6b63\u898f\u8868\u73fe\u3092\u4f7f\u7528\u3057\u3066\u5909\u6570\u3092\u7f6e\u63db\u3002<\/p>\n<\/li>\n<li>\n<p>\u6761\u4ef6\u304c\u9069\u7528\u3067\u304d\u306a\u3044\u5834\u5408\u3092\u5b89\u5168\u306b\u30b9\u30ad\u30c3\u30d7\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<div class=\"sect3\">\n<h4 id=\"_process_query\u95a2\u6570\">6.2.4. process_query\u95a2\u6570<\/h4>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-python\" data-lang=\"python\">def process_query(query, data):\r\n    pattern = r\"\\[\\d*(:\\d*)?(:\\d*)?\\]\"\r\n    match = re.fullmatch(pattern, query) \r\n    unsupported = any(op in query for op in [\":\", \"..\", \"[?\"])\r\n    if match or not unsupported:\r\n        jsonpath_expr = parse(query)\r\n        result = [match.value for match in jsonpath_expr.find(data)]\r\n        return result\r\n    elif \"$..*\"==query:\r\n        return recursive_descent(data)\r\n    \"\"\"\r\n    Process a JSONPath query, supporting normal processing, recursive descent,\r\n    slicing, and filtering.\r\n    \"\"\"\r\n    if \"$..\" in query:\r\n        if \"[?\" in query:\r\n            # Handle filtering\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            condition = query.split(\"[?\")[-1].rstrip(\"]\")\r\n            items = flatten(recursive_descent(data, key))\r\n            return manual_filter(items, condition)\r\n        elif \"[\" in query and \":\" in query:\r\n            # Handle slicing\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            slice_expr = query.split(\"[\")[-1].rstrip(\"]\")\r\n            start, end = (slice_expr.split(\":\") + [None])[:2]\r\n            start = int(start) if start else None\r\n            end = int(end) if end else None\r\n            items = flatten(recursive_descent(data, key))\r\n            return items[start:end]\r\n        elif \"[\" in query:\r\n            # Handle single index\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            index = int(query.split(\"[\")[-1].rstrip(\"]\"))\r\n            items = flatten(recursive_descent(data, key))\r\n            return [items[index]] if -len(items) &lt;= index &lt; len(items) else []\r\n        else:\r\n            # Handle recursive descent without filters\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            return flatten(recursive_descent(data, key))\r\n    else:\r\n        # Normal JSONPath processing\r\n        try:\r\n            jsonpath_expr = parse(query)\r\n            return [match.value for match in jsonpath_expr.find(data)]\r\n        except Exception as e:\r\n            return f\"Error: {e}\"<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><strong>\u76ee\u7684<\/strong>:<br \/>\n                                    <code>process_query<\/code><br \/>\n                                    \u95a2\u6570\u306f\u3001JSONPath\u30af\u30a8\u30ea\u3092\u53d7\u3051\u53d6\u308a\u3001\u305d\u306e\u30af\u30a8\u30ea\u306b\u57fa\u3065\u3044\u3066JSON\u30c7\u30fc\u30bf\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u3092\u76ee\u7684\u3068\u3057\u3066\u3044\u307e\u3059\u3002\u6a19\u6e96\u7684\u306aJSONPath\u30af\u30a8\u30ea\u3060\u3051\u3067\u306a\u304f\u3001\u518d\u5e30\u7684\u306a\u63a2\u7d22\u3084\u6761\u4ef6\u4ed8\u304d\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3068\u3044\u3063\u305f\u9ad8\u5ea6\u306a\u30af\u30a8\u30ea\u3082\u30b5\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002\n                                <\/p>\n<\/li>\n<li>\n<p><strong>\u7279\u5fb4<\/strong>:<\/p>\n<div class=\"olist arabic\">\n<ol class=\"arabic\">\n<li>\n<p><strong>\u6a19\u6e96\u30af\u30a8\u30ea\u306e\u76f4\u63a5\u51e6\u7406<\/strong>:<br \/>\n                                                <code>jsonpath-ng<\/code> \u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u30b5\u30dd\u30fc\u30c8\u3059\u308b\u30af\u30a8\u30ea\uff08\u4f8b: <code>$.store.book[*]<\/code><br \/>\n                                                \u3084 <code>$.store.book[0:2]<\/code>\uff09\u306f\u3001\u76f4\u63a5\u51e6\u7406\u3055\u308c\u307e\u3059\u3002\n                                            <\/p>\n<\/li>\n<li>\n<p><strong>\u30ab\u30b9\u30bf\u30e0\u30ed\u30b8\u30c3\u30af\u306e\u4f7f\u7528<\/strong>:<br \/>\n                                                \u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u5bfe\u5fdc\u3067\u304d\u306a\u3044\u9ad8\u5ea6\u306a\u30af\u30a8\u30ea\uff08\u4f8b: \u518d\u5e30\u7684\u63a2\u7d22 <code>$..*<\/code> \u3084\u6761\u4ef6\u4ed8\u304d\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0<br \/>\n                                                <code>[?@.price&lt;10]<\/code>\uff09\u306f\u3001\u95a2\u6570\u5185\u306e\u30ab\u30b9\u30bf\u30e0\u30ed\u30b8\u30c3\u30af\u3092\u5229\u7528\u3057\u3066\u51e6\u7406\u3057\u307e\u3059\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u67d4\u8edf\u306a\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0<\/strong>:<br \/>\n                                                \u6a19\u6e96\u30af\u30a8\u30ea\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u3084\u3001\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u306a\u3044\u30af\u30a8\u30ea\u304c\u63d0\u4f9b\u3055\u308c\u305f\u5834\u5408\u3067\u3082\u3001\u9069\u5207\u306a\u4ee3\u66ff\u30ed\u30b8\u30c3\u30af\u3092\u5b9f\u884c\u307e\u305f\u306f\u30a8\u30e9\u30fc\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u8fd4\u3057\u307e\u3059\u3002\n                                            <\/p>\n<\/li>\n<\/ol><\/div>\n<\/li>\n<li>\n<p><strong>\u91cd\u8981\u306a\u30ed\u30b8\u30c3\u30af<\/strong>:<\/p>\n<\/li>\n<li>\n<p><strong>\u30af\u30a8\u30ea\u306e\u89e3\u6790<\/strong>:<br \/>\n                                    \u6b63\u898f\u8868\u73fe\u3067\u30af\u30a8\u30ea\u3092\u89e3\u6790\u3057\u3001\u6a19\u6e96\u7684\u306a\u69cb\u6587\u304b\u3069\u3046\u304b\u3092\u5224\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u518d\u5e30\u7684\u63a2\u7d22\u306e\u5bfe\u5fdc<\/strong>:<br \/>\n                                    <code>$..*<\/code> \u306e\u3088\u3046\u306a\u5168\u8981\u7d20\u691c\u7d22\u30af\u30a8\u30ea\u306f\u3001<code>recursive_descent<\/code> \u95a2\u6570\u3092\u4f7f\u7528\u3057\u3066\u51e6\u7406\u3057\u307e\u3059\u3002\n                                <\/p>\n<\/li>\n<li>\n<p><strong>\u6761\u4ef6\u4ed8\u304d\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0<\/strong>:<br \/>\n                                    <code>[?@.key&lt;value]<\/code> \u306e\u3088\u3046\u306a\u6761\u4ef6\u4ed8\u304d\u30af\u30a8\u30ea\u3092\u52d5\u7684\u306b\u8a55\u4fa1\u3057\u3001\u8a72\u5f53\u3059\u308b\u8981\u7d20\u3092\u62bd\u51fa\u3057\u307e\u3059\u3002\n                                <\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u4f8b<\/strong>:<\/p>\n<\/li>\n<li>\n<p>\u30af\u30a8\u30ea: <code>$.store.book[*]<\/code><br \/>\n                                    \u3059\u3079\u3066\u306e\u672c\u3092\u53d6\u5f97\u3002<\/p>\n<\/li>\n<li>\n<p>\u30af\u30a8\u30ea: <code>$..book[?@.price&lt;10]<\/code><br \/>\n                                    \u4fa1\u683c\u304c10\u672a\u6e80\u306e\u672c\u3092\u6761\u4ef6\u4ed8\u304d\u3067\u53d6\u5f97\u3002<\/p>\n<\/li>\n<\/ul><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect2\">\n<h3 id=\"_jsonpath_ng\u304c\u30b5\u30dd\u30fc\u30c8\u3059\u308bjsonpath\u306e\u8868\u8a18\u3068\u57fa\u672c\u95a2\u6570\u306e\u4f7f\u7528\u4f8b\">6.3. jsonpath_ng\u304c\u30b5\u30dd\u30fc\u30c8\u3059\u308bJSONPath\u306e\u8868\u8a18\u3068\u57fa\u672c\u95a2\u6570\u306e\u4f7f\u7528\u4f8b<\/h3>\n<table class=\"tableblock frame-all grid-all stretch\">\n<colgroup>\n<col style=\"width: 25%;\">\n<col style=\"width: 25%;\">\n<col style=\"width: 25%;\">\n<col style=\"width: 25%;\">\n                    <\/colgroup>\n<thead>\n<tr>\n<th class=\"tableblock halign-left valign-top\">#<\/th>\n<th class=\"tableblock halign-left valign-top\">JSONPath Syntax<\/th>\n<th class=\"tableblock halign-left valign-top\">Python Example<\/th>\n<th class=\"tableblock halign-left valign-top\">\u691c\u7d22\u6761\u4ef6<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">1<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$.store.book[*]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\"><code>parse(\"$.store.book[*]\").find(data)<\/code><\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u5546\u5e97\u306e\u3059\u3079\u3066\u306e\u66f8\u7c4d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">2<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$.store.book[*].author<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\"><code>parse(\"$.store.book[*].author\").find(data)<\/code><\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u5546\u5e97\u306e\u3059\u3079\u3066\u306e\u66f8\u7c4d\u306e\u8457\u8005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">3<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..author<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\"><code>parse(\"$..author\").find(data)<\/code><\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">JSON\u5185\u306e\u3059\u3079\u3066\u306e\u8457\u8005<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">4<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[2]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">`parse(&#8220;$..book[2]&#8221;)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\uff13\u756a\u76ee\u306e\u66f8\u7c4d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">5<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[-1]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">`parse(&#8220;$..book[-1]&#8221;)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u6700\u5f8c\u306e\u66f8\u7c4d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">6<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[:2]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">`parse(&#8220;$..book[:2]&#8221;)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u6700\u521d\u304b\u30892\u518a\u306e\u66f8\u7c4d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">7<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[1:3]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">`parse(&#8220;$..book[:2]&#8221;)<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u6700\u521d\u304b\u30892\u518a\u3081\u307e\u3067\u306e\u66f8\u7c4d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">8<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$.store..price<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\"><code>parse(\"$.store..price\").find(data)<\/code><\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u5546\u5e97\u306e\u3059\u3079\u3066\u306e\u4fa1\u683c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">9<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..book[?@.price&lt;10]<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u624b\u52d5\u3067\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\uff1a<code>manual_filter(data, '@.price&lt;10')<\/code><\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u4fa1\u683c\u304c10\u672a\u6e80\u306e\u66f8\u7c4d<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">8<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">$..*<\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">\u518d\u5e30\u7684\u691c\u7d22\uff1a<code>recursive_descent(data)<\/code><\/p>\n<\/td>\n<td class=\"tableblock halign-left valign-top\">\n<p class=\"tableblock\">JSON\u5185\u306e\u3059\u3079\u3066\u306e\u8981\u7d20<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-shell\" data-lang=\"shell\">Test: 1. All books\r\nQuery: $.store.book[*]\r\nResult: [\r\n    { 'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95}, \r\n    {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99}, \r\n    {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0 - 553 - 21311 - 3', 'price': 8.99}, \r\n    {'category': 'fiction', 'author': 'J.R.R.Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0 - 395 - 19395 - 8', 'price': 22.99}\r\n]\r\n\r\nTest: 2. Authors of all books\r\nQuery: $.store.book[*].author\r\nResult: ['Nigel Rees', 'Evelyn Waugh', 'Herman Melville', 'J. R. R. Tolkien']       \r\n\r\nTest: 3. All authors in the document(recursive descent)\r\nQuery: $..author\r\nResult: ['Nigel Rees', 'Evelyn Waugh', 'Herman Melville', 'J. R. R. Tolkien']       \r\n\r\nTest: 4. The third book\r\nQuery: $..book[2]\r\nResult: [\r\n    { 'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99 }]\r\n\r\nTest: 5. The last book(negative index)\r\nQuery: $..book[-1]\r\nResult: [\r\n    { 'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0-395-19395-8', 'price': 22.99 }\r\n]\r\n\r\nTest: 6. The first two books\r\nQuery: $..book[: 2]\r\nResult: [\r\n    { 'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95 }, \r\n    { 'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99 }\r\n]\r\n\r\nTest: 7. The second and the third books\r\nQuery: $..book[1: 3]\r\nResult: [\r\n    { 'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99 }, \r\n    { 'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99 }\r\n]\r\n\r\nTest: 8. All prices in a store\r\nQuery: $.store..price\r\nResult: [8.95, 12.99, 8.99, 22.99, 399]\r\n\r\n\r\nTest: 9. Filter books cheaper than 10\r\nQuery: $..book[? @.price &lt; 10]\r\nResult: [\r\n    { 'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95 }, \r\n    { 'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99 }\r\n]\r\n\r\nTest: 10. All elements recursively\r\nQuery: $..*\r\nResult: [\r\n    {\r\n    '   book': [\r\n            { 'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95 }, \r\n            { 'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99 }, \r\n            { 'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0-553-21311-3', 'price': 8.99 }, \r\n            { 'category': 'fiction', 'author': 'J. R. R. Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0 - 395 - 19395 - 8', 'price': 22.99}\r\n        ], \r\n        'bicycle': {'color': 'red', 'price': 399}\r\n    }, \r\n    [\r\n        {'category': 'reference', 'author': 'Nigel Rees', 'title': 'Sayings of the Century', 'price': 8.95}, \r\n        {'category': 'fiction', 'author': 'Evelyn Waugh', 'title': 'Sword of Honour', 'price': 12.99}, \r\n        {'category': 'fiction', 'author': 'Herman Melville', 'title': 'Moby Dick', 'isbn': '0 - 553 - 21311 - 3', 'price': 8.99}, \r\n        {'category': 'fiction', 'author': 'J.R.R.Tolkien', 'title': 'The Lord of the Rings', 'isbn': '0 - 395 - 19395 - 8', 'price': 22.99}\r\n    ], \r\n    'reference', \r\n    'Nigel Rees', \r\n    'Sayings of the Century', \r\n    8.95, \r\n    'fiction', \r\n    'Evelyn Waugh', \r\n    'Sword of Honour', \r\n    12.99, \r\n    'fiction', \r\n    'Herman Melville', \r\n    'Moby Dick', \r\n    '0 - 553 - 21311 - 3', \r\n    8.99, \r\n    'fiction', \r\n    'J.R.R.Tolkien', \r\n    'The Lord of the Rings', \r\n    '0 - 395 - 19395 - 8', \r\n    22.99, \r\n    {'color': 'red', 'price': 399}, \r\n    'red', \r\n    399\r\n]<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"sect2\">\n<h3 id=\"_\u30d7\u30ed\u30b0\u30e9\u30e0\u30bd\u30fc\u30b9\">6.4. \u30d7\u30ed\u30b0\u30e9\u30e0\u30bd\u30fc\u30b9<\/h3>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-PythonPython\" data-lang=\"PythonPython\">from jsonpath_ng import parse\r\nimport re\r\n\r\n# Sample JSON data\r\ndata = {\r\n    \"store\": {\r\n        \"book\": [\r\n            {\r\n                \"category\": \"reference\",\r\n                \"author\": \"Nigel Rees\",\r\n                \"title\": \"Sayings of the Century\",\r\n                \"price\": 8.95,\r\n            },\r\n            {\r\n                \"category\": \"fiction\",\r\n                \"author\": \"Evelyn Waugh\",\r\n                \"title\": \"Sword of Honour\",\r\n                \"price\": 12.99,\r\n            },\r\n            {\r\n                \"category\": \"fiction\",\r\n                \"author\": \"Herman Melville\",\r\n                \"title\": \"Moby Dick\",\r\n                \"isbn\": \"0-553-21311-3\",\r\n                \"price\": 8.99,\r\n            },\r\n            {\r\n                \"category\": \"fiction\",\r\n                \"author\": \"J. R. R. Tolkien\",\r\n                \"title\": \"The Lord of the Rings\",\r\n                \"isbn\": \"0-395-19395-8\",\r\n                \"price\": 22.99,\r\n            },\r\n        ],\r\n        \"bicycle\": {\"color\": \"red\", \"price\": 399},\r\n    }\r\n}\r\n\r\n\r\ndef flatten(results):\r\n    \"\"\"Flatten nested lists into a single list.\"\"\"\r\n    flat = []\r\n    for item in results:\r\n        if isinstance(item, list):\r\n            flat.extend(flatten(item))\r\n        else:\r\n            flat.append(item)\r\n    return flat\r\n\r\n\r\ndef recursive_descent(data, key=None, handle_normal=True):\r\n    \"\"\"\r\n    Traverse the JSON structure recursively to find all instances of a given key.\r\n    If no key is provided, collect all elements (for recursive wildcards like $..*).\r\n    \"\"\"\r\n    if handle_normal and key:\r\n        query = f\"$..{key}\" if key != \"*\" else \"$..*\"\r\n        try:\r\n            jsonpath_expr = parse(query)\r\n            result = [match.value for match in jsonpath_expr.find(data)]\r\n            return result\r\n        except Exception:\r\n            pass  # Fallback to explicit handling if JSONPath fails\r\n\r\n    results = []\r\n    if isinstance(data, dict):\r\n        for k, v in data.items():\r\n            if key is None or k == key:\r\n                results.append(v)\r\n            results.extend(recursive_descent(v, key, handle_normal=False))\r\n    elif isinstance(data, list):\r\n        for item in data:\r\n            results.extend(recursive_descent(item, key, handle_normal=False))\r\n    return results\r\n\r\n\r\ndef manual_filter(data, condition):\r\n    \"\"\"\r\n    Apply a manual filter condition (e.g., @.price &lt; 10) to a list of items.\r\n    Safely evaluates the condition for dictionary items.\r\n    \"\"\"\r\n    filtered = []\r\n    for item in data:\r\n        if isinstance(item, dict):\r\n            try:\r\n                # Replace @.key with item['key'] dynamically for safe access\r\n                condition_replaced = re.sub(r\"@\\.(\\w+)\", r'item[\"\\1\"]', condition)\r\n                if eval(condition_replaced):\r\n                    filtered.append(item)\r\n            except (KeyError, AttributeError, SyntaxError):\r\n                # Skip items where the condition cannot be applied\r\n                pass\r\n    return filtered\r\n\r\n\r\ndef process_query(query, data):\r\n    pattern = r\"\\[\\d*(:\\d*)?(:\\d*)?\\]\"\r\n    match = re.fullmatch(pattern, query) \r\n    unsupported = any(op in query for op in [\":\", \"..\", \"[?\"])\r\n    if match or not unsupported:\r\n        jsonpath_expr = parse(query)\r\n        result = [match.value for match in jsonpath_expr.find(data)]\r\n        return result\r\n    elif \"$..*\"==query:\r\n        return recursive_descent(data)\r\n    \"\"\"\r\n    Process a JSONPath query, supporting normal processing, recursive descent,\r\n    slicing, and filtering.\r\n    \"\"\"\r\n    if \"$..\" in query:\r\n        if \"[?\" in query:\r\n            # Handle filtering\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            condition = query.split(\"[?\")[-1].rstrip(\"]\")\r\n            items = flatten(recursive_descent(data, key))\r\n            return manual_filter(items, condition)\r\n        elif \"[\" in query and \":\" in query:\r\n            # Handle slicing\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            slice_expr = query.split(\"[\")[-1].rstrip(\"]\")\r\n            start, end = (slice_expr.split(\":\") + [None])[:2]\r\n            start = int(start) if start else None\r\n            end = int(end) if end else None\r\n            items = flatten(recursive_descent(data, key))\r\n            return items[start:end]\r\n        elif \"[\" in query:\r\n            # Handle single index\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            index = int(query.split(\"[\")[-1].rstrip(\"]\"))\r\n            items = flatten(recursive_descent(data, key))\r\n            return [items[index]] if -len(items) &lt;= index &lt; len(items) else []\r\n        else:\r\n            # Handle recursive descent without filters\r\n            key = query.split(\"..\")[-1].split(\"[\")[0]\r\n            return flatten(recursive_descent(data, key))\r\n    else:\r\n        # Normal JSONPath processing\r\n        try:\r\n            jsonpath_expr = parse(query)\r\n            return [match.value for match in jsonpath_expr.find(data)]\r\n        except Exception as e:\r\n            return f\"Error: {e}\"\r\n\r\n# Test cases\r\nqueries = [\r\n    {\"query\": \"$.store.book[*]\", \"description\": \"1. All books\"},\r\n    {\"query\": \"$.store.book[*].author\", \"description\": \"2. Authors of all books\"},\r\n    {\"query\": \"$..author\", \"description\": \"3. All authors in the document (recursive descent)\"},\r\n    {\"query\": \"$..book[2]\", \"description\": \"4. The third book\"},\r\n    {\"query\": \"$..book[-1]\", \"description\": \"5. The last book (negative index)\"},\r\n    {\"query\": \"$..book[:2]\", \"description\": \"6. The first two books\"},\r\n    {\"query\": \"$..book[1:3]\", \"description\": \"7. The second and the third books\"},\r\n    {\"query\": \"$.store..price\", \"description\": \"8. All prices in a store\"},\r\n    {\"query\": \"$..book[?@.price&lt;10]\", \"description\": \"9. Filter books cheaper than 10\"},\r\n    {\"query\": \"$..*\", \"description\": \"10. All elements recursively\"},\r\n]\r\n\r\nfor test in queries:\r\n    print(f\"Test: {test['description']}\")\r\n    result = process_query(test[\"query\"], data)\r\n    print(f\"Query: {test['query']}\\nResult: {result}\\n\")<\/code><\/pre>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div id=\"toc\" class=\"toc2\">\n<div id=\"toctitle\">\u76ee\u6b21<\/div>\n<ul class=\"sectlevel1\">\n<li><a href=\"#_jsonpath\u306e\u6a19\u6e96\u5316rfc_9535\">1. JSONPath\u306e\u6a19\u6e96\u5316\uff1aRFC 9535<\/a><\/li>\n<li><a href=\"#_jsonpath\u5f0f\u306e\u6982\u8981\">2. JSONPath\u5f0f\u306e\u6982\u8981<\/a><\/li>\n<li><a href=\"#_json_pointer\u3068\u306e\u9055\u3044\">3. JSON Pointer\u3068\u306e\u9055\u3044<\/a><\/li>\n<li><a href=\"#_xpath\u3068\u306e\u6bd4\u8f03\">4. XPath\u3068\u306e\u6bd4\u8f03<\/a><\/li>\n<li><a href=\"#_python\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u9078\u629e\">5. Python\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u9078\u629e<\/a>\n<ul class=\"sectlevel2\">\n<li><a href=\"#_\u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8abf\u67fb\">5.1. \u30e9\u30a4\u30d6\u30e9\u30ea\u306e\u8abf\u67fb<\/a><\/li>\n<li><a href=\"#_\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6642\u306e\u554f\u984c\">5.2. \u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u6642\u306e\u554f\u984c<\/a><\/li>\n<li><a href=\"#_\u6700\u7d42\u7684\u306a\u9078\u629e\">5.3. \u6700\u7d42\u7684\u306a\u9078\u629e<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#_jsonpath\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a73\u7d30\u89e3\u8aac\">6. JSONPath\u30c6\u30b9\u30c8\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u8a73\u7d30\u89e3\u8aac<\/a>\n<ul class=\"sectlevel2\">\n<li><a href=\"#_\u30b5\u30f3\u30d7\u30ebjson\u30c7\u30fc\u30bf\">6.1. \u30b5\u30f3\u30d7\u30ebJSON\u30c7\u30fc\u30bf<\/a><\/li>\n<li><a href=\"#_\u5404\u95a2\u6570\u306e\u8a73\u7d30\u89e3\u8aac\">6.2. \u5404\u95a2\u6570\u306e\u8a73\u7d30\u89e3\u8aac<\/a><\/li>\n<li><a href=\"#_jsonpath_ng\u304c\u30b5\u30dd\u30fc\u30c8\u3059\u308bjsonpath\u306e\u8868\u8a18\u3068\u57fa\u672c\u95a2\u6570\u306e\u4f7f\u7528\u4f8b\">6.3.<br \/>\n                            jsonpath_ng\u304c\u30b5\u30dd\u30fc\u30c8\u3059\u308bJSONPath\u306e\u8868\u8a18\u3068\u57fa\u672c\u95a2\u6570\u306e\u4f7f\u7528\u4f8b<\/a><\/li>\n<li><a href=\"#_\u30d7\u30ed\u30b0\u30e9\u30e0\u30bd\u30fc\u30b9\">6.4. \u30d7\u30ed\u30b0\u30e9\u30e0\u30bd\u30fc\u30b9<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul><\/div>\n<\/div>\n<div id=\"footer\">\n<div id=\"footer-text\">\n        Last updated 2024-12-16 13:56:02 +0900\n    <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Views: 25 JSONPath\u3068Python\u74b0\u5883\u6e96\u5099 JSONPath\u306f\u3001JSON\u30c7\u30fc\u30bf\u3092\u691c\u7d22\u304a\u3088\u3073\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3059\u308b\u305f\u3081\u306e\u30af\u30a8\u30ea\u8a00\u8a9e\u3067\u3059\u3002JSON Pointer\u3084XPath\u306b\u89e6\u767a\u3055\u308c\u3001\u7279\u306bJSON\u30c7\u30fc\u30bf\u69cb\u9020\u306e\u67d4 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":13973,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[50,11],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/13968"}],"collection":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13968"}],"version-history":[{"count":22,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/13968\/revisions"}],"predecessor-version":[{"id":14002,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/posts\/13968\/revisions\/14002"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=\/wp\/v2\/media\/13973"}],"wp:attachment":[{"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sambuichi.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}