[].endpoints.[*].ip
does the trick...answered my own question
function: tavern.testutils.helpers:validate_content
extra_kwargs:
comparisons:
- jmespath: "search(members, @)"
array[?some_property == 'value1']
search(foo, {"foo": "bar"}) -> "bar"
With a JSON object like the following
[
{
"type": {
text: "company"
},
"data": {
"name": "Company A",
"logo": "company_a.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-a.com"
}
},
{
"type": {
text: "company"
},
"data": {
"name": "Company B",
"logo": "company_b.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-b.com"
}
},
{
"type": {
text: "employee"
},
"data": {
"name": "John Smith",
"dob": "1/16/1990",
"position": "CEO"
}
},
{
"type": {
text: "company"
},
"data": {
"name": "Company C",
"logo": "company_c.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-c.com"
}
},
{
"type": {
text: "employee"
},
"data": {
"name": "Oprah",
"dob": "1/16/1990",
"position": "TV Personality"
}
}
]
Is there a JMESpath query I can use to reformat the above string to display more like this?
{
companies: [
{
"type": {
text: "company"
},
"data": {
"name": "Company A",
"logo": "company_a.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-a.com"
}
},
{
"type": {
text: "company"
},
"data": {
"name": "Company B",
"logo": "company_b.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-b.com"
}
},
{
"type": {
text: "company"
},
"data": {
"name": "Company C",
"logo": "company_c.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-c.com"
}
}
],
employees: [
{
"type": {
text: "employee"
},
"data": {
"name": "John Smith",
"dob": "1/16/1990",
"position": "CEO"
}
},
{
"type": {
text: "employee"
},
"data": {
"name": "Oprah",
"dob": "1/16/1990",
"position": "TV Personality"
}
}
]
}
Basically I want to filter the objects by the type.text
, and display the top level object containing that type.
I've been playing with the contains
function, which does allow me to filter, however the return result is only the current node, I need to return the containing parent node.
Is this possible with JMESpath?
[SomePathWhereItemsAre.item][]
takes care of a single item, and of multiple items - always returns a list (of one or more).
{
"0": {
"type": {
"text": "company"
},
"data": {
"name": "Company A",
"logo": "company_a.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-a.com"
}
},
"1": {
"type": {
"text": "company"
},
"data": {
"name": "Company B",
"logo": "company_b.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-b.com"
}
},
"2": {
"type": {
"text": "employee"
},
"data": {
"name": "John Smith",
"dob": "1/16/1990",
"position": "CEO"
}
},
"3": {
"type": {
"text": "company"
},
"data": {
"name": "Company C",
"logo": "company_c.png",
"divisions": "Division A, Division B, Division C",
"homepage": "company-c.com"
}
},
"4": {
"type": {
"text": "employee"
},
"data": {
"name": "Oprah",
"dob": "1/16/1990",
"position": "TV Personality"
}
}
}
{ companies: null, employees: null }
I'd like to use jmespath to transform json from:
{
"order": {
"order_type": "online",
"item": [
{
"item_nbr": 1,
"item_type": "so",
"mlog": [
{
"id":"1",
"timestamp":"2019-12-13"
},
{
"id":"2",
"timestamp":"2019-12-13"
}
]
},
{
"item_nbr": 2,
"item_type": "so",
"mlog": [
{
"id":"1",
"timestamp":"2019-12-13"
},
{
"id":"3",
"timestamp":"2019-12-13"
}
]
}
],
"mlog": [
{
"id":"5",
"timestamp":"2019-12-13"
},
{
"id":"6",
"timestamp":"2019-12-13"
}
]
}
}
to
[
{
"order": {
"order_type": "online",
"item": [
{
"item_nbr": 1,
"item_type": "so",
"mlog": [
{
"id": "1",
"timestamp": "2019-12-13"
},
{
"id": "2",
"timestamp": "2019-12-13"
}
]
}
],
"mlog": [
{
"id": "5",
"timestamp": "2019-12-13"
},
{
"id": "6",
"timestamp": "2019-12-13"
}
]
}
},
{
"order": {
"order_type": "online",
"item": [
{
"item_nbr": 2,
"item_type": "so",
"mlog": [
{
"id": "1",
"timestamp": "2019-12-13"
},
{
"id": "3",
"timestamp": "2019-12-13"
}
]
}
],
"mlog": [
{
"id": "5",
"timestamp": "2019-12-13"
},
{
"id": "6",
"timestamp": "2019-12-13"
}
]
}
},
{
"order": {
"order_type": "online",
"mlog": [
{
"id": "5",
"timestamp": "2019-12-13"
},
{
"id": "6",
"timestamp": "2019-12-13"
}
]
}
}
]