JOLT - filtering array based on object value - jolt

how can I do this?
This is the array....
Can you please help me?
Can you please give me the answer???? Thanks a lot
{
"results": {
"data": [
{
"name": "xx",
"typeRelationship": [
{
"relationship": "parent",
"type": {
"id": "yyyyy",
}
}
],
"id": "xxxxxxxx"
},
{
"name": "yy",
"typeRelationship": [
{
"relationshipType": "parent",
"type": {
"id": "CCCC"
}
},
{
"relationshipType": "child",
"service": {
"id": "DDDD"
}
},
{
"relationshipType": "child",
"service": {
"id": "xxxxxxxx"
}
}
],
"id": "yyyyy"
}
]
}}
expected:
This is expected:
{
"data" : [ {
"id" : "xxxx",
"href" : "xxxxxx",
"relation":"parent"
} ]
}
For some reason I need to type so it does let me update!!!

This works.
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"type": {
"id": {
"xxxx": {
"#3": "data[]"
}
}
}
}
}
}
}
]
Edit 1
The below spec moves all the values which as id=xxxxx to the data array.
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"type": {
"*": {
"id": {
"xxxx": {
"#(2)": "data[]",
"#(4,relation)": "data[&3].relation"
}
}
}
}
}
}
}
}
]

This totally works.
Thanks.
Can you please let me know what is 2? 3? 4?
Because my array is a bit different and I want to fix those numbers but does not work....
{
"results": {
"data": [
{
"name": "xx",
"typeRelationship": [
{
"relationship": "parent",
"type": {
"id": "yyyyy",
}
}
],
"id": "xxxxxxxx"
},
{
"name": "yy",
"typeRelationship": [
{
"relationshipType": "parent",
"type": {
"id": "CCCC"
}
},
{
"relationshipType": "child",
"service": {
"id": "DDDD"
}
},
{
"relationshipType": "child",
"service": {
"id": "xxxxxxxx"
}
}
],
"id": "yyyyy"
}
]
}
}
expected:
{
"rows" : [ {
"rowdata" : {
"relationshipType" : "child",
"Name" : "yy",
"id" : "yyyyy"
}
} ]
}

Related

Facing issue with JOLT transformation with nested array

I have a JSON input :
{
"id": "Root_ID",
"Item": [
{
"id": "ID_1",
"characteristic": [
{
"name": "char1",
"value": "PRE1"
},
{
"name": "char2",
"value": "2050-01-01"
}
]
},
{
"id": "ID_2",
"characteristic": [
{
"name": "char1",
"value": "PRE2"
},
{
"name": "char2",
"value": "2050-01-02"
}
]
}
]
}
which needs to be converted by using a Jolt transformation spec to the following output :
{
"id": "Root_ID",
"Item": [
{
"id": "ID_1",
"char1": "PRE1",
"char2": "2050-01-01"
},
{
"id": "ID_2",
"char1": "PRE2",
"char2": "2050-01-02"
}
]
}
Currently, I'm using this spec :
[
{
"operation": "shift",
"spec": {
"id": "id",
"Item": {
"*": {
"characteristic": {
"*": {
"name": {
"char1": {
"#(2,value)": "item[#3].char1"
},
"char2": {
"#(2,value)": "item[#3].char2"
}
}
}
}
}
}
}
}
]
which does not produce the desired result.
Can you please help me prepare a correct spec to handle this issue ?
Edit : What if I'd like to get the following JSON result ?
{
"id": "Root_ID",
"Item": [
{
"id": "ID_1",
"char1": "PRE1"
},
{
"id": "ID_2",
"char1": "PRE2",
"char2": "2050-01-02"
}
]
}
You can use the following shift transformation spec in which #value and #name are matched reciprocally such as
[
{
"operation": "shift",
"spec": {
"id": "&",
"Item": {
"*": {
"id": "&2[&1].&",// you can reduce two levels based on the inner identifier 4,3 -> 2,1
"char*": {
"*": {
"#value": "&4[&3].#name" // &4 copies the literal "Item" after going four levels up the tree, [&3] generates array-wise result(array of objects) after going three levels up the tree to reach the level of the indexes of the "Item" array
}
}
}
}
}
}
]
Edit : You can alternatively use the following spec for the case in which you need to return char2 within the all objects but the first :
[
{
"operation": "shift",
"spec": {
"id": "&",
"Item": {
"0": {// stands for the first index
"id": "&2[&1].&",
"char*": {
"*": {
"name": {
"char1": {
"#2,value": "&6[&5].#3,name"
}
}
}
}
},
"*": {
"id": "&2[&1].&",
"char*": {
"*": {
"#value": "&4[&3].#name"
}
}
}
}
}
}
]

Moving one array into json objects defined in another array - JOLT Transformation

I have my input defined as
{
"lineId": "1",
"Collection": {
"services": [
{
"Code": "TB",
"Type": [
"Data"
]
},
{
"Code": "MAGTB",
"Type": [
"Data"
]
}
]
},
"promotions": [
{
"Id": "1"
},
{
"Id": "2"
}
]
}
I would like to get my output as
{
"lineId": "1",
"Collection": {
"services": [
{
"Code": "TB",
"Type": [
"Data"
],
"promotions": [
{
"Id": "1"
},
{
"Id": "2"
}
]
},
{
"Code": "TB2",
"Type": [
"Data"
],
"promotions": [
{
"Id": "1"
},
{
"Id": "2"
}
]
}
]
}
}
Any help would be appreciated.
I am new to JOLT. And I'm having trouble navigating to the second array from inside the first.
Incomplete transformation that I tried:
[
{
"operation": "shift",
"spec": {
"Collection": {
"services": {
"*": "Collection.services[].&",
"#(3,lineId)": "lineId",
"#(3,promotions)":{
"*":
}
}
}
}
}
]
edit: Tried this now
[
{
"operation": "shift",
"spec": {
"Collection": {
"services": {
"*": "Collection.services[]",
// "*": "&",
"#(3,lineId)": "lineId",
"#(3,promotions)": {
"*": {
"Id": "Id"
}
}
}
}
}
}
]
I just have to figure out a way to move the Id list inside the objects in services array.
edit2:
[
{
"operation": "shift",
"spec": {
"Collection": {
"services": {
"*": {
"*": "Collection.services[&1].&",
"#(3,lineId)": "Collection.services[&1].lineId",
"#(3,promotions)": "Collection.services[&1].promotions"
}
}
}
}
}
]
I think this is the spec you're looking for?
[
{
"operation": "shift",
"spec": {
"lineId": "lineId",
"Collection": {
"services": {
"*": {
"#(3,promotions)": "Collection.services[&1].promotions",
"*": "Collection.services[&1].&"
}
}
}
}
}
]

Transform list array inside an array in json

I am new to JOLT transformation. I am trying to create a transform spec.
I have an list of categories in the object where I need to only transform few details.
My sample code and spec re shown below.
In "0/SYS_CATALOG_DESCRIPTION" list, I need to convert it to a String based on the lang, i.e for en_US, I need to get AA Products
end result will be "_description" : "AA Products"
The "subCategories" should give me the following result:
"subCategories": [
{
"_id": "ce_155584",
"_parentIds": ["ce_128375"],
"_description": "Filters" //based on lang = en_US
}
]
Sample JSON:
{
"total": 16,
"max_score": 2.2809339,
"hits": [
{
"_index": "bosch-dms-frontend-service_en_us_1558584002",
"_type": "categories",
"_id": "ce_128375",
"_score": 2.2809339,
"_source": {
"_parentIds": [
"1234"
],
"0/SYS_CATALOG_DESCRIPTION": [
{
"lang": "de_DE",
"value": "AA Produkte"
},
{
"lang": "en_US",
"value": "AA Products"
}
],
"subCategories": [
{
"_index": "bosch-dms-frontend-service_en_us_1558584002",
"_type": "categories",
"_id": "ce_155584",
"_score": 2.2809339,
"_source": {
"_parentIds": [
"ce_128375"
],
"0/SYS_CATALOG_DESCRIPTION": [
{
"lang": "en_US",
"value": "Filters"
},
{
"lang": "zh_CN",
"value": "AA Filters (CN)"
}
],
"0/SYS_SYSTEMNAME": "AA_Filters"
}
}
]
}
}
]
}
SPEC:
[
{
"operation": "shift", // shift operation
"spec": {
"hits": {
"*": {
"_id": "_id",
"_source": {
"_parentIds": "_parentIds",
"0/SYS_CATALOG_DESCRIPTION": "_description",
}
}
}
}
}
]
The end result will be
{
"_id" : "ce_128375",
"_parentIds" : [ "1234" ],
"_description" : "AA Products (BR)",
"subCategories": [
{
"_id": "ce_155584",
"_score": 2.2809339,
"_parentIds": ["ce_128375"],
"_description" : "Filters"
}
]
}
I tried several ways but could not achieve the result.
Thank you.
Check if this spec is what you need:
[
{
"operation": "shift", // shift operation
"spec": {
"hits": {
"*": {
"_id": ["&",
"subCategories.[]._parentIds[]"],
"_source": {
"_parentIds": "&",
"0/SYS_CATALOG_DESCRIPTION": {
"*": {
"lang": {
"en_US": {
"#(2,value)": "_description"
}
}
}
},
"subCategories": {
"*": {
"_id": "subCategories.[&1].&",
"_score": "subCategories.[&1].&",
"_source": {
"0/SYS_CATALOG_DESCRIPTION": {
"*": {
"lang": {
"en_US": {
"#(2,value)": "subCategories.[&6]._description"
}
}
}
}
}
}
}
}
}
}
}
}
]

Need JOLT spec file for transfer of complex JSON

I have a complex JSON object (I've simplified it for this example) that I cannot figure out the JOLT transform JSON for. Does anybody have any ideas of what the JOLT spec file should be?
Original JSON
[
{
"date": {
"isoDate": "2019-03-22"
},
"application": {
"name": "SiebelProject"
},
"applicationResults": [
{
"reference": {
"name": "Number of Code Lines"
},
"result": {
"value": 44501
}
},
{
"reference": {
"name": "Transferability"
},
"result": {
"grade": 3.1889542208002064
}
}
]
},
{
"date": {
"isoDate": "2019-03-21"
},
"application": {
"name": "SiebelProject"
},
"applicationResults": [
{
"reference": {
"name": "Number of Code Lines"
},
"result": {
"value": 45000
}
},
{
"reference": {
"name": "Transferability"
},
"result": {
"grade": 3.8
}
}
]
}
]
Desired JSON after transformation and sorting by "Name" ASC, "Date" DESC
[
{
"Name": "SiebelProject",
"Date": "2019-03-22",
"Number of Code Lines": 44501,
"Transferability" : 3.1889542208002064
},
{
"Name": "SiebelProject",
"Date": "2019-03-21",
"Number of Code Lines": 45000,
"Transferability" : 3.8
}
]
I couldn't find a way to do the sort (I'm not even sure you can sort descending in JOLT) but here's a spec to do the transform:
[
{
"operation": "shift",
"spec": {
"*": {
"date": {
"isoDate": "[#3].Date"
},
"application": {
"name": "[#3].Name"
},
"applicationResults": {
"*": {
"reference": {
"name": {
"Number of Code Lines": {
"#(3,result.value)": "[#7].Number of Code Lines"
},
"Transferability": {
"#(3,result.grade)": "[#7].Transferability"
}
}
}
}
}
}
}
}
]
After that there are some tools (like jq I think) that could do the sort.

"Client invalid path, not found in rest table" does anyone know what this Sabre's error means

I want to use this API service:
https://developer.sabre.com/docs/read/rest_apis/air/book/create_passenger_name_record
and the server responds with this json:
{
"status": "NotProcessed",
"type": "Application",
"errorCode": "ERR.2SG.CLIENT.INVALID_REQUEST",
"timeStamp": "2017-09-12T13:21:29.522-05:00",
"message": "Client invalid path, not found in rest table"
}
As mentioned in the comments, the endpoint is not right. After fixing that you'd get many different errors, for example you are referencing a Profile ID ABCDEF that doesn't exist.
I've modified that request so you'd get a successful response.
v2.0.0/passenger/records?mode=create
{
"CreatePassengerNameRecordRQ": {
"targetCity": "XXXX",
"TravelItineraryAddInfo": {
"AgencyInfo": {
"Ticketing": {
"TicketType": "7TAW/"
}
},
"CustomerInfo": {
"ContactNumbers": {
"ContactNumber": [
{
"Phone": "817-555-1212",
"PhoneUseType": "H"
}
]
},
"PersonName": [
{
"GivenName": "TEST",
"Surname": "TEST"
}
]
}
},
"AirBook": {
"OriginDestinationInformation": {
"FlightSegment": [
{
"ArrivalDateTime": "2018-07-20T14:20",
"DepartureDateTime": "2018-07-20T12:57",
"FlightNumber": "2404",
"NumberInParty": "1",
"ResBookDesigCode": "Y",
"Status": "NN",
"DestinationLocation": {
"LocationCode": "LAX"
},
"MarketingAirline": {
"Code": "AA",
"FlightNumber": "2404"
},
"MarriageGrp": "O",
"OriginLocation": {
"LocationCode": "DFW"
}
}
]
}
},
"AirPrice": {
"PriceRequestInformation": {
"OptionalQualifiers": {
"PricingQualifiers": {
"PassengerType": [
{
"Code": "ADT",
"Quantity": "1"
}
]
}
}
}
},
"MiscSegment": {
"DepartureDateTime": "2018-10-29",
"NumberInParty": 1,
"Status": "NN",
"Type": "OTH",
"OriginLocation": {
"LocationCode": "LAS"
},
"Text": "TEST",
"VendorPrefs": {
"Airline": {
"Code": "AA"
}
}
},
"SpecialReqDetails": {
"AddRemark": {
"RemarkInfo": {
"FOP_Remark": {
"Type": "CHECK",
"CC_Info": {
"Suppress": true,
"PaymentCard": {
"AirlineCode": "YY",
"CardSecurityCode": "1234",
"Code": "VI",
"ExpireDate": "2012-12",
"ExtendedPayment": "12",
"ManualApprovalCode": "123456",
"Number": "4123412341234123",
"SuppressApprovalCode": true
}
}
},
"Remark": [
{
"Type": "Historical",
"Text": "TEST HISTORICAL REMARK"
},
{
"Type": "Invoice",
"Text": "TEST INVOICE REMARK"
},
{
"Type": "Itinerary",
"Text": "TEST ITINERARY REMARK"
},
{
"Type": "Hidden",
"Text": "TEST HIDDEN REMARK"
}
]
}
},
"AirSeat": {
"Seats": {
"Seat": [
{
"NameNumber": "1.1",
"Preference": "AN",
"SegmentNumber": "1"
}
]
}
},
"SpecialService": {
"SpecialServiceInfo": {
"Service": [
{
"SSR_Code": "OSI",
"PersonName": {
"NameNumber": "1.1"
},
"Text": "TEST",
"VendorPrefs": {
"Airline": {
"Code": "UA"
}
}
}
]
}
}
},
"PostProcessing": {
"RedisplayReservation": true,
"EndTransaction": {
"Source": {
"ReceivedFrom": "SWS TEST"
}
}
}
}
}