Thirteen cases: node-red-contrib-jsonpath

Literal examples of JSONPath from node-red-contrib-jsonpath documentation.

[{"id":"59c4f489.a63b0c","type":"inject","name":"","topic":"","payload":"","payloadType":"none","repeat":"","crontab":"","once":false,"x":117,"y":365,"z":"85632268.7a9ce","wires":[["1ae0ecdd.e51f13"]]},{"id":"1ae0ecdd.e51f13","type":"function","name":"books","func":"msg.payload =\n{\n  \"store\": {\n    \"book\": [\n      {\n        \"category\": \"reference\",\n        \"author\": \"Nigel Rees\",\n        \"title\": \"Sayings of the Century\",\n        \"price\": 8.95\n      },{\n        \"category\": \"fiction\",\n        \"author\": \"Evelyn Waugh\",\n        \"title\": \"Sword of Honour\",\n        \"price\": 12.99\n      },{\n        \"category\": \"fiction\",\n        \"author\": \"Herman Melville\",\n        \"title\": \"Moby Dick\",\n        \"isbn\": \"0-553-21311-3\",\n        \"price\": 8.99\n      },{\n        \"category\": \"fiction\",\n        \"author\": \"J. R. R. Tolkien\",\n        \"title\": \"The Lord of the Rings\",\n        \"isbn\": \"0-395-19395-8\",\n        \"price\": 22.99\n      }\n    ],\n    \"bicycle\": {\n      \"color\": \"red\",\n      \"price\": 19.95\n    }\n  }\n};\nvar output = [];\nfor(i=0; i<13; i++){output.push(msg);};\n\nreturn output;","outputs":"13","x":269,"y":364,"z":"85632268.7a9ce","wires":[["270fdf2d.d8f02"],["7c51889a.83ae78"],["edfeb543.120148"],["d5cefc8b.2a31"],["30f98275.cf067e"],["45f3374b.ba0cc8"],["6993c7d2.966c38"],["80f1de9e.7f0e2"],["2e5ba2cf.d1a45e"],["194b809a.e6b47f"],["d86fdb99.279028"],["b884723c.477b9"],["b88e9d33.47716"]]},{"id":"270fdf2d.d8f02","type":"jsonpath","expression":"$.store.book[*].author","split":false,"name":"$.store.book[*].author","x":600,"y":100,"z":"85632268.7a9ce","wires":[["66c2e1ce.993d2"]]},{"id":"66c2e1ce.993d2","type":"debug","name":"the authors of all books in the store","active":true,"console":"false","complete":"false","x":887,"y":100,"z":"85632268.7a9ce","wires":[]},{"id":"7c51889a.83ae78","type":"jsonpath","expression":"$..author","split":false,"name":"$..author","x":560,"y":150,"z":"85632268.7a9ce","wires":[["ac752014.538ae"]]},{"id":"ac752014.538ae","type":"debug","name":"all authors","active":true,"console":"false","complete":"false","x":811,"y":150,"z":"85632268.7a9ce","wires":[]},{"id":"edfeb543.120148","type":"jsonpath","expression":"$.store.*","split":false,"name":"$.store.*","x":556,"y":200,"z":"85632268.7a9ce","wires":[["cf531a93.30ace8"]]},{"id":"cf531a93.30ace8","type":"debug","name":"all things in store","active":true,"console":"false","complete":"false","x":833,"y":200,"z":"85632268.7a9ce","wires":[]},{"id":"d5cefc8b.2a31","type":"jsonpath","expression":"$.store..price","split":false,"name":"$.store..price","x":572,"y":250,"z":"85632268.7a9ce","wires":[["5edcd400.a1232c"]]},{"id":"5edcd400.a1232c","type":"debug","name":"the price of everything in the store","active":true,"console":"false","complete":"false","x":889,"y":250,"z":"85632268.7a9ce","wires":[]},{"id":"30f98275.cf067e","type":"jsonpath","expression":"$..book[2]","split":false,"name":"$..book[2]","x":564,"y":300,"z":"85632268.7a9ce","wires":[["b7ccc994.483338"]]},{"id":"b7ccc994.483338","type":"debug","name":"the third book","active":true,"console":"false","complete":"false","x":825,"y":300,"z":"85632268.7a9ce","wires":[]},{"id":"45f3374b.ba0cc8","type":"jsonpath","expression":"$..book[(@.length-1)]","split":false,"name":"$..book[(@.length-1)]","x":600,"y":350,"z":"85632268.7a9ce","wires":[["19524f79.e6adb1"]]},{"id":"19524f79.e6adb1","type":"debug","name":"the last book in order","active":true,"console":"false","complete":"false","x":851,"y":350,"z":"85632268.7a9ce","wires":[]},{"id":"6993c7d2.966c38","type":"jsonpath","expression":"$..book[-1:]","split":false,"name":"$..book[-1:]","x":567,"y":400,"z":"85632268.7a9ce","wires":[["ccc241f6.333dc"]]},{"id":"ccc241f6.333dc","type":"debug","name":"the last book in order","active":true,"console":"false","complete":"false","x":847,"y":400,"z":"85632268.7a9ce","wires":[]},{"id":"80f1de9e.7f0e2","type":"jsonpath","expression":"$..book[0,1]","split":false,"name":"$..book[0,1]","x":567,"y":450,"z":"85632268.7a9ce","wires":[["eb685403.1497a8"]]},{"id":"eb685403.1497a8","type":"debug","name":"the first two books","active":true,"console":"false","complete":"false","x":838,"y":450,"z":"85632268.7a9ce","wires":[]},{"id":"2e5ba2cf.d1a45e","type":"jsonpath","expression":"$..book[:2]","split":false,"name":"$..book[:2]","x":563,"y":500,"z":"85632268.7a9ce","wires":[["f1e664b.f0e1998"]]},{"id":"f1e664b.f0e1998","type":"debug","name":"the first two books","active":true,"console":"false","complete":"false","x":837,"y":500,"z":"85632268.7a9ce","wires":[]},{"id":"194b809a.e6b47f","type":"jsonpath","expression":"$..book[?(@.isbn)]","split":false,"name":"$..book[?(@.isbn)]","x":587,"y":550,"z":"85632268.7a9ce","wires":[["66a298de.995d68"]]},{"id":"66a298de.995d68","type":"debug","name":"filter all books with isbn number","active":true,"console":"false","complete":"false","x":873,"y":550,"z":"85632268.7a9ce","wires":[]},{"id":"d86fdb99.279028","type":"jsonpath","expression":"$..book[?(@.price<10)]","split":false,"name":"$..book[?(@.price<10)]","x":599,"y":600,"z":"85632268.7a9ce","wires":[["e7ac77fc.185388"]]},{"id":"e7ac77fc.185388","type":"debug","name":"filter all books cheapier than 10","active":true,"console":"false","complete":"false","x":871,"y":600,"z":"85632268.7a9ce","wires":[]},{"id":"b884723c.477b9","type":"jsonpath","expression":"$..[?(@.price>19)]","split":false,"name":"$..[?(@.price>19)]","x":587,"y":650,"z":"85632268.7a9ce","wires":[["c69cde4b.39632"]]},{"id":"c69cde4b.39632","type":"debug","name":"categories with things more expensive than 19","active":true,"console":"false","complete":"false","x":918,"y":650,"z":"85632268.7a9ce","wires":[]},{"id":"b88e9d33.47716","type":"jsonpath","expression":"$..*","split":false,"name":"$..*","x":550,"y":700,"z":"85632268.7a9ce","wires":[["872ea750.78d158"]]},{"id":"872ea750.78d158","type":"debug","name":"all members of JSON structure","active":true,"console":"false","complete":"false","x":874,"y":700,"z":"85632268.7a9ce","wires":[]},{"id":"1fb7b53e.e0484b","type":"comment","name":"SEE ALSO","info":"1. http://goessner.net/articles/JsonPath/\n2. https://www.npmjs.org/package/JSONPath\n3. https://groups.google.com/forum/#!topic/node-red/CbWA7t3JHS4/discussion\n4. https://github.com/kmi/node-red-contrib-jsonpath","x":83,"y":730,"z":"85632268.7a9ce","wires":[]}]

Flow Info

Created 10 years, 4 months ago
Updated 9 years, 3 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x13)
  • function (x1)
  • inject (x1)
Other

Tags

  • JSON
  • XPath
  • JSONPath
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option