-
Notifications
You must be signed in to change notification settings - Fork 103
Open
Description
I tested on both Python version and Javascript version on JMSPath webpage, same results:
Testing query: users[?id == `1`].contacts[?type == `email`].value | [0]
JSON Data: {
"users": [
{
"id": 1,
"name": "Alice",
"contacts": [
{
"type": "email",
"value": "[email protected]"
},
{
"type": "phone",
"value": "+1234567890"
}
]
},
{
"id": 2,
"name": "Bob",
"contacts": [
{
"type": "email",
"value": "[email protected]"
}
]
}
]
}
Debug: JMESPath version: 1.0.1
Debug: Python version: 3.10.16 | packaged by conda-forge | (main, Dec 5 2024, 14:16:10) [GCC 13.3.0]
Debug: Users with id == 1: [{'id': 1, 'name': 'Alice', 'contacts': [{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]}]
Debug: Raw contact objects: [[{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]]
Debug: Flattened contacts: [{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]
Debug: All contact types: ['email', 'phone']
Debug: Raw type values: ['email', 'phone']
Debug: Contacts with type == email: []
Debug: Minimal test: None
Test failed!
Query: users[?id == `1`].contacts[?type == `email`].value | [0]
Expected: [email protected]
Got: None
Testing query: users[?id == `1`].contacts[][?type == `email`].value | [0]
JSON Data: {
"users": [
{
"id": 1,
"name": "Alice",
"contacts": [
{
"type": "email",
"value": "[email protected]"
},
{
"type": "phone",
"value": "+1234567890"
}
]
},
{
"id": 2,
"name": "Bob",
"contacts": [
{
"type": "email",
"value": "[email protected]"
}
]
}
]
}
Debug: JMESPath version: 1.0.1
Debug: Python version: 3.10.16 | packaged by conda-forge | (main, Dec 5 2024, 14:16:10) [GCC 13.3.0]
Debug: Users with id == 1: [{'id': 1, 'name': 'Alice', 'contacts': [{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]}]
Debug: Raw contact objects: [[{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]]
Debug: Flattened contacts: [{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]
Debug: All contact types: ['email', 'phone']
Debug: Raw type values: ['email', 'phone']
Debug: Contacts with type == email: []
Debug: Minimal test: None
Test failed!
Query: users[?id == `1`].contacts[][?type == `email`].value | [0]
Expected: [email protected]
Got: None
Testing query: users[?id == `1`].contacts[*][?type == `email`].value | [0]
JSON Data: {
"users": [
{
"id": 1,
"name": "Alice",
"contacts": [
{
"type": "email",
"value": "[email protected]"
},
{
"type": "phone",
"value": "+1234567890"
}
]
},
{
"id": 2,
"name": "Bob",
"contacts": [
{
"type": "email",
"value": "[email protected]"
}
]
}
]
}
Debug: JMESPath version: 1.0.1
Debug: Python version: 3.10.16 | packaged by conda-forge | (main, Dec 5 2024, 14:16:10) [GCC 13.3.0]
Debug: Users with id == 1: [{'id': 1, 'name': 'Alice', 'contacts': [{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]}]
Debug: Raw contact objects: [[{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]]
Debug: Flattened contacts: [{'type': 'email', 'value': '[email protected]'}, {'type': 'phone', 'value': '+1234567890'}]
Debug: All contact types: ['email', 'phone']
Debug: Raw type values: ['email', 'phone']
Debug: Contacts with type == email: []
Debug: Minimal test: None
Test failed!
Query: users[?id == `1`].contacts[*][?type == `email`].value | [0]
Expected: [email protected]
Got: []
Manual filtering workaround:
Manual result: [email protected]
From JSON above what query should be used to extract [email protected] without providing array index in query but rely only on filtering
Metadata
Metadata
Assignees
Labels
No labels