I need to find json path for the given json structure
{
"name": "ninja",
"contry": "India",
"Account": [
{
"id": "123",
"orgId": 223,
"investment": [
{
"invetmentId": "111",
"name": "India tech",
"performance": [
{
"id": "123",
"performanceSet": [
{
"amount": "210",
"currency": "YEN"
},
{
"amount": "231",
"currency": "USD"
},
{
"amount": "233",
"currency": "USD"
},
{
"amount": "250",
"currency": "IND"
}
],
"loyal": "250"
}
]
}
]
}
]
}
Here I need to get the amount from performanceSet where the currency is USD and will only return the amount where it got first occurrence of such value?
It should return
[
"231"
]
I don't think that is possible using jsonpath.
You can use following jsonpath.
$.Account[0].investment[0].performance[0].performanceSet[?(#.currency=='USD')]
This will give you
[
{
"amount": "231",
"currency": "USD"
},
{
"amount": "233",
"currency": "USD"
}
]
Here you can programmitically select the first element and further read the amount.
You can try converting the json to XML using js2xml and then use xpath on the same. XPath is much more powerful
Related
I am new at JSON path request and I have a quite complex request to build.
I work with a JSOn strusture having 2 arrays like this example :
{
"WideXml": {
"Guid": "9cf379c5-dc12-4a63-922a-d242efe9a777",
"ApplicationGuid": "24df8af4-58c2-40dd-8ce8-70becb2df96f",
"Action": "Approval",
"Values": {
"Date": {
"TimeStamp": "2021-11-23T04:00:00Z",
"Value": [{
"Guid": "9c64fb06-60f5-4541-a006-3a92ac576e13",
"Value": "6.7169265747070313",
"Unit": "t",
"UserFields": {
"Field": [{
"Value": "131",
"Key": "BWART"
},
{
"Value": "14702-00-BULK",
"Key": "MATNR"
}
]
}
},
{
"Guid": "6c048d70-1521-4fa1-a462-669730d6b1ed",
"Value": "84.824371337890625",
"Unit": "t",
"UserFields": {
"Field": [{
"Value": "261",
"Key": "BWART"
}, {
"Value": "14366-00-WA0R",
"Key": "MATNR"
}]
}
}
]
}
}
}
}
I need to find the "MATNR" code by searching with Key = 'BWART' and Value = '131'.
I can find the Field document by the request
$.WideXml.Values.Date.Value[*].UserFields.Field[?(#.Key=='BWART' && #.Value=='131')]
But I don't manage to build the query to get the MATNR after having this result...
Can someone help?
Regards.
if the key BWART is always at the same index position i.e 0 in this example, you can try the expression
$.WideXml.Values.Date.Value[?(#.UserFields.Field[0].Key== "BWART" && #.UserFields.Field[0].Value == "131")].UserFields.Field[*]
I have the following object and I want to create a schema for it that handles nested objects - what's the best way using graphql:
{
"type": "product",
"id": "411e2a2b-37e8-421e-adb8-2e038751d263",
"name": "Hazel",
"slug": "hazel",
"sku": "ENGINEERED3",
"manage_stock": false,
"description": "Abstract, sculptural, refined and edgy with a modern twist. Its symmetrical, spoked structure generates a clever geometric presence, which works well in a contemporary environment..",
"price": [
{
"amount": 11200,
"currency": "AUD",
"includes_tax": true
}
],
"status": "live",
"commodity_type": "physical",
"meta": {
"timestamps": {
"created_at": "2019-05-09T13:30:10+00:00",
"updated_at": "2019-05-09T13:45:11+00:00"
},
"display_price": {
"with_tax": {
"amount": 11200,
"currency": "AUD",
"formatted": "$112.00"
},
"without_tax": {
"amount": 11200,
"currency": "AUD",
"formatted": "$112.00"
}
},
"stock": {
"level": 0,
"availability": "out-stock"
}
}
}
It seems as though graphql wants a separate type per nested object - is that true?
I have the following document
{
"id": "46c0ccbc-7a05-41dc-bc33-e9d1e69b74fa",
"_id": "5bf8b90f9568cf0001463719",
"vendor": "XXX",
"updatedAt": "2018-11-26T02:17:59.311Z",
"locales": [
{
"title": "351011",
"description": " ",
"categories": [
"Children",
"Accessories"
],
"brand": null,
"images": [
"https://lp.example.com/app006prod?set=source[02_0690165_001_001],type[PRODUCT],device[hdpi],quality[80],ImageVersion[2018081]&call=url[file:/product/main]"
],
"country": "SE",
"currency": "SEK",
"language": "en",
"variants": [
{
"artno": "example",
"urls": [
"https://www.example.com/en_sek/children/baby-newborn/product.cotton-cashmere-newborn-mittens-red.0690165001.html"
],
"price": 120,
"stock": 15,
"attributes": {
"size": "One Size",
"color": "Burgundy"
}
}
]
}
],
"_rid": "QEwcAOOf+rUHAAAAAAAAAA==",
"_self": "dbs/QEwcAA==/colls/QEwcAOOf+rU=/docs/QEwcAOOf+rUHAAAAAAAAAA==/",
"_etag": "\"00000e00-0000-0000-0000-5bfc890d0000\"",
"_attachments": "attachments/",
"_ts": 1543276813
}
I am trying to write a simple query that lists all documents that has "Children" as one of its Categories
I tried the following query but it does not work
SELECT * FROM c where c.locales.categories = "Children"
I am assuming I am referencing the subarrays wrong but what is the right way to write this query?
You need to use the ARRAY_CONTAINS function.
Try this: SELECT * FROM c where ARRAY_CONTAINS(c.locales[0].categories, "Children")
I'm currently testing with the Bargain Finder Max REST API. I'm aware that there are versions of the BFM API specifically implementing alternative dates and alternative airports, but I was wondering if there was a way to combine alternative dates and alternative airports into a single request. I've tried things like
{
"OTA_AirLowFareSearchRQ": {
"AvailableFlightsOnly": true,
"POS": {
"Source": [{
"PseudoCityCode":"F9CE",
"RequestorID": {
"Type": "1",
"ID": "1",
"CompanyName": {
"Code": "TN",
"CodeContext": "Context"
}
}
}]
},
"OriginDestinationInformation": [{
"DepartureDateTime": "2018-04-07T00:00:00",
"OriginLocation": {
"LocationCode": "DTW"
},
"DestinationLocation": {
"LocationCode": "ORD"
}
}],
"TravelerInfoSummary": {
"AirTravelerAvail": [{
"PassengerTypeQuantity": [{
"Code": "ADT",
"Quantity": 1
}]
}],
"PriceRequestInformation": {
"CurrencyCode": "USD"
}
},
"TPA_Extensions": {
"IntelliSellTransaction": {
"RequestType": {
"Name": "AD1"
}
}
}
}
}
But this only returns alternate dates for DTW -> ORD, the original origin and destination airports.
I'm also trying to figure out how to get more results with the alternative date BFM API. Running the query
{
"OTA_AirLowFareSearchRQ": {
"AvailableFlightsOnly": true,
"POS": {
"Source": [{
"PseudoCityCode":"F9CE",
"RequestorID": {
"Type": "1",
"ID": "1",
"CompanyName": {
"Code": "TN",
"CodeContext": "Context"
}
}
}]
},
"OriginDestinationInformation": [{
"DepartureDateTime": "2018-04-07T00:00:00",
"OriginLocation": {
"LocationCode": "DTW"
},
"DestinationLocation": {
"LocationCode": "ORD"
}
}],
"TravelPreferences": {
"TPA_Extensions": {
"NumTrips": {
"Number": 100
}
}
},
"TravelerInfoSummary": {
"AirTravelerAvail": [{
"PassengerTypeQuantity": [{
"Code": "ADT",
"Quantity": 1
}]
}],
"PriceRequestInformation": {
"CurrencyCode": "USD"
}
},
"TPA_Extensions": {
"IntelliSellTransaction": {
"RequestType": {
"Name": "AD1"
}
}
}
}
}
But this only returns one itinerary per day.
Could anyone help me with these issues? Thanks kindly in advance!
When doing BFM you have different qualifiers that may help with searching for alternate airports, like AlternateAirportCities or SisterDestinationLocation, but these don't seem to be enabled for BFM Alternate Dates.
Instead, what you may use instead of the airport codes, is the actual city where it present. In your example you go from Detroit (DTW) to Chicago (ORD), but if you change, for example, the destination to Chicago city (CHI) you can get CHICAGO OHARE (ORD) as well as CHICAGO MIDWAY (MDW).
A few examples:
LON instead of LHR, LCY, LGW
NYC instead of JFK, LGA, EWR
PAR instead of CDG, ORY
MOW instead of DME, SVO, VKO
BUE instead of EZE, AEP
WAS instead of DCA, IAD
I have been using OpenRefine 2.6 Beta 1 w/o problems since its release, and later, with the reconciliation service at:
http://reconcile.freebaseapps.com/reconcile
However, in the past fee days, I have not been able to use it all. If I go to the URL:
http://reconcile.freebaseapps.com/
and type the multiple query:
{
"query": "Ford",
"type": "/people/person",
"properties": [
{
"pid": "/people/person/place_of_birth",
"v": "Detroit"
}
]
}
I obtain:
{
"result": [
{
"id": "/m/0j8pb6y",
"name": "Ford",
"type": [
{
"id": "/people/person",
"name": "Person"
},
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/geography/mountaineer",
"name": "Mountaineer"
}
],
"notable": [],
"score": 1.1546246,
"match": false
},
{
"id": "/m/01vd3gv",
"name": "Ford",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/music/artist",
"name": "Musical Artist"
}
],
"notable": [],
"score": 1.0330245999999998,
"match": false
},
{
"id": "/m/0cmdhzt",
"name": "James Meredith",
"type": [
{
"id": "/common/topic",
"name": "Topic"
},
{
"id": "/people/person",
"name": "Person"
},
{
"id": "/military/military_person",
"name": "Military Person"
},
{
"id": "/people/deceased_person",
"name": "Deceased Person"
}
],
"notable": [],
"score": 0.0681692,
"match": false
}
],
"duration": 369
}
But if I try a simple query:
{
"query": "Ford"
}
I get:
Status: error Error:undefined
Any insights into what's happening with the reconciliation service? Is there any other service I could use to replace freebaseapps.com?
Thanks
Try this in Queries Parameter at http://reconcile.freebaseapps.com/
{
"q0": {
"query": "Ford"
}
}
For some reason, single queries are not accepted in Query Parameter but in Queries Parameter in the format above. I have not tested this in OpenRefine, so you might have to modify it.
I don't know for certain about the date, but Freebase was announced earlier this year as being shutdown by Jun 30, 2015, for some services. Maybe service is intermittent until full shutdown? Sorry, this answer probably doesn't help much.