Title: `@property` incorrectly excludes array index 0 because javascript treats `0` as false · Issue #245 · JSONPath-Plus/JSONPath · GitHub
Open Graph Title: `@property` incorrectly excludes array index 0 because javascript treats `0` as false · Issue #245 · JSONPath-Plus/JSONPath
X Title: `@property` incorrectly excludes array index 0 because javascript treats `0` as false · Issue #245 · JSONPath-Plus/JSONPath
Description: Consider a sample JSON Document: { "store": { "book": [{ "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", ...
Open Graph Description: Consider a sample JSON Document: { "store": { "book": [{ "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Eve...
X Description: Consider a sample JSON Document: { "store": { "book": [{ "category": "reference", "author": "Nigel Rees", "title": "Saying...
Opengraph URL: https://github.com/JSONPath-Plus/JSONPath/issues/245
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`@property` incorrectly excludes array index 0 because javascript treats `0` as false","articleBody":"Consider a sample JSON Document: \n```\n {\n \"store\": {\n \"book\": [{\n \"category\": \"reference\",\n \"author\": \"Nigel Rees\",\n \"title\": \"Sayings of the Century\",\n \"price\": 8.95\n },\n {\n \"category\": \"fiction\",\n \"author\": \"Evelyn Waugh\",\n \"title\": \"Sword of Honour\",\n \"price\": 12.99\n },\n {\n \"category\": \"fiction\",\n \"author\": \"Herman Melville\",\n \"title\": \"Moby Dick\",\n \"isbn\": \"0-553-21311-3\",\n \"price\": 8.99\n },\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 \"bicycle\": {\n \"color\": \"red\",\n \"price\": 19.95\n }\n }\n}\n```\n**Issue:**\nWhen using a filter operation with `@property` , JSONPath Plus incorrectly excludes array elements whose property (array index) is 0, because in JavaScript if(0) means it returns false.\n\nExample JSONPath expression:\n\n``` $.store.bicycle[?(@property)] ```\n\n**Output**\n```\nred,\n19.95\n```\nThis works correctly because the children have string keys (\"color\" , \"price\"), which are truthy. Since each child has a property key , the filter operation for `@property` evaluate to true ,and therefore all child nodes are included.\n\nBut,\n```\n$.store.book[?(@property)]\n```\nHere, book is an array and then the `@property` for the array elements are going to be the array indices.\n\n- For the first element , `@property` is 0 (its array index)\n- For the second element, `@property` is 1 and so on.\n\nBut, here the problem is since for the first element array index is 0 , `@property` = 0, JavaScript evaluates if(0) as false. So, the first book element is incorrectly excluded. Only array elements at index 1,2,3 appear, because their properties are `1, 2, 3` , which are truthy. But the first array element should also be included since it also has a property.\n\n**JSONPath Expression** \n\n```\n$.store.book[?(@property)]\n```\n**Actual Output** : Output lists except the first array element\n```\n {\n \"category\": \"fiction\",\n \"author\": \"Evelyn Waugh\",\n \"title\": \"Sword of Honour\",\n \"price\": 12.99\n },\n {\n \"category\": \"fiction\",\n \"author\": \"Herman Melville\",\n \"title\": \"Moby Dick\",\n \"isbn\": \"0-553-21311-3\",\n \"price\": 8.99\n },\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\n**Expected Output** : Output should list all array elements\n {\n \"category\": \"reference\",\n \"author\": \"Nigel Rees\",\n \"title\": \"Sayings of the Century\",\n \"price\": 8.95\n },\n {\n \"category\": \"fiction\",\n \"author\": \"Evelyn Waugh\",\n \"title\": \"Sword of Honour\",\n \"price\": 12.99\n },\n {\n \"category\": \"fiction\",\n \"author\": \"Herman Melville\",\n \"title\": \"Moby Dick\",\n \"isbn\": \"0-553-21311-3\",\n \"price\": 8.99\n },\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\n\n\nEnvironment\n- JSONPath-Plus version: jsonpath-plus@10.3.0\n\nDesktop\n - OS: Ubuntu (Linux)\n - Node Version: v18.13.0\n\n","author":{"url":"https://github.com/Laavanja19","@type":"Person","name":"Laavanja19"},"datePublished":"2025-12-08T07:30:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/245/JSONPath/issues/245"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6360d902-3b8e-6dd5-4602-f8e4f65aab15 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CC28:3CE303:1592FDE:1E873C6:696F6093 |
| html-safe-nonce | 85e6a6d43c08b1d38891574f31759a94556352cd2a3000898cd05f0f6b10740a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQzI4OjNDRTMwMzoxNTkyRkRFOjFFODczQzY6Njk2RjYwOTMiLCJ2aXNpdG9yX2lkIjoiMjc0NTMwMDQwMTEwMjIxNzM2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 910dabb0f2f693982c3aaed63e81b0354be2d20b32da7a3a01d31e6c31ed78cf |
| hovercard-subject-tag | issue:3705024167 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/JSONPath-Plus/JSONPath/245/issue_layout |
| twitter:image | https://opengraph.githubassets.com/110fdeb2aa113eb15fa5f504971b093a6cfb9b1ae309489226495f43f8306942/JSONPath-Plus/JSONPath/issues/245 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/110fdeb2aa113eb15fa5f504971b093a6cfb9b1ae309489226495f43f8306942/JSONPath-Plus/JSONPath/issues/245 |
| og:image:alt | Consider a sample JSON Document: { "store": { "book": [{ "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Eve... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Laavanja19 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 774d0922d2c4577043d2dab90427344eb4c6ce1d5579acb1dd504cff1a7e46f8 |
| turbo-cache-control | no-preview |
| go-import | github.com/JSONPath-Plus/JSONPath git https://github.com/JSONPath-Plus/JSONPath.git |
| octolytics-dimension-user_id | 67874603 |
| octolytics-dimension-user_login | JSONPath-Plus |
| octolytics-dimension-repository_id | 1716525 |
| octolytics-dimension-repository_nwo | JSONPath-Plus/JSONPath |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1716525 |
| octolytics-dimension-repository_network_root_nwo | JSONPath-Plus/JSONPath |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 650acea592f12d1bd8931d44546c209e0b06ed6e |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width