Using the sample json response from jsonplaceholder.com, I would like to perform a Jolt transformation on the unnamed array that is returned.
However, using the jolt demo I have only been able to transform the array after naming the array ("records" in this example), and wrapping with curly braces. Like this:
Json Input:
{
"records": [
{
"id": 1,
"name": "Leanne Graham",
"username": "Bret",
"email": "Sincere#april.biz",
"address": {
"street": "Kulas Light",
"suite": "Apt. 556",
"city": "Gwenborough",
"zipcode": "92998-3874",
"geo": {
"lat": "-37.3159",
"lng": "81.1496"
}
},
"phone": "1-770-736-8031 x56442",
"website": "hildegard.org",
"company": {
"name": "Romaguera-Crona",
"catchPhrase": "Multi-layered client-server neural-net",
"bs": "harness real-time e-markets"
}
},
{
"id": 2,
"name": "Ervin Howell",
"username": "Antonette",
"email": "Shanna#melissa.tv",
"address": {
"street": "Victor Plains",
"suite": "Suite 879",
"city": "Wisokyburgh",
"zipcode": "90566-7771",
"geo": {
"lat": "-43.9509",
"lng": "-34.4618"
}
},
"phone": "010-692-6593 x09125",
"website": "anastasia.net",
"company": {
"name": "Deckow-Crist",
"catchPhrase": "Proactive didactic contingency",
"bs": "synergize scalable supply-chains"
}
}
]
}
Jolt Spec:
[
{
"operation": "shift",
"spec": {
"records": {
"*": {
"id": "records[&1].user-id",
"username": "records[&1].user-username",
"email": "records[&1].user-email",
"address": {
"street": "records[&2].user-street",
"suite": "records[&2].user-suite",
"city": "records[&2].user-city",
"zipcode": "records[&2].user-zipcode"
}
}
}
}
}
]
My example's goal is to flatten the object hierarchy returned in the response, while maintaining the basic [{}, {}, ...] structure.
How can I achieve this when the input is an unnamed json array?
I just realized the answer after posting...
Here is my revised spec for anyone that is interested:
[
{
"operation": "shift",
"spec": {
"*": {
"id": "[&1].user-id",
"username": "[&1].user-username",
"email": "[&1].user-email",
"address": {
"street": "[&2].user-street",
"suite": "[&2].user-suite",
"city": "[&2].user-city",
"zipcode": "[&2].user-zipcode"
}
}
}
}
]
Simply match after declaring spec ("spec": { "*": { "), then access the unnamed array with [&1], [&2], etc
below one works, but not flattens
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"id": "[&1].user-id",
"username": "[&1].user-username",
"email": "[&1].user-email",
"address": {
"street": "[&2].user-street",
"suite": "[&2].user-suite",
"city": "[&2].user-city",
"zipcode": "[&2].user-zipcode"
}
}
}
}
}
]
Related
I have a Java Map which is deserialized into immutable objects from a json similar to below and has multiple levels of nesting. I have a second Map containing alternate values for some of the strings. The second map has the value appended to the key for the nested levels to differentiate between different elements in an array. I would like to replace the values in the first map using the values found in the second map. Are there any suggestions for the approach that could used to solve the below?
{
"product": "Internet",
"version": 3.1,
"releaseDate": "2014-06-25T00:00:00.000Z",
"person": {
"id": 12345,
"name": "John Doe",
"phones": {
"home": "800-123-4567",
"mobile": "877-123-1234"
},
"email": [
"jd#example.com",
"jd#example.org"
],
"dateOfBirth": "1980-01-02T00:00:00.000Z",
"registered": true,
"emergencyContacts": [
{
"name": "Jane Doe",
"phone": "888-555-1212",
"relationship": "spouse"
},
{
"name": "Justin Doe",
"phone": "877-123-1212",
"relationship": "parent"
}
]
}
}
Map containing alternate values
{
"product": "Strong Internet",
"person.name=John Doe" : "Barry Richards",
"person.emergencyContacts.name=Jane Doe" : "Jane Richards"
}
Resulting Map
{
"product": "Strong Internet",
"version": 3.1,
"releaseDate": "2014-06-25T00:00:00.000Z",
"person": {
"id": 12345,
"name": "Barry Richards",
"phones": {
"home": "800-123-4567",
"mobile": "877-123-1234"
},
"email": [
"jd#example.com",
"jd#example.org"
],
"dateOfBirth": "1980-01-02T00:00:00.000Z",
"registered": true,
"emergencyContacts": [
{
"name": "Jane Richards",
"phone": "888-555-1212",
"relationship": "spouse"
},
{
"name": "Justin Doe",
"phone": "877-123-1212",
"relationship": "parent"
}
]
}
}
I have an array which I have to iterate and append object that is outside the list to each of the object inside list. It is not happening properly. Since offerings is an array if it has multiple objects to each object I need to have typeId of that object.
Request:
[
{
"offers": [
{
"type": {
"id": "5"
},
"offerings": [
{
"id": "10"
},
{
"id": "9"
}
]
},
{
"type": {
"id": "3"
},
"offerings": [
{
"id": "11"
}
]
},
{
"type": {
"id": "2"
},
"offerings": [
{
"id": "14"
},
{
"id": "16"
}
]
}
]
}
]
My spec:
[
{
"operation": "shift",
"spec": {
"*": {
"offers": {
"*": {
"type": {
"id": "[&4].[&2].typeId"
},
"offerings": {
"*": {
"id": "[&3].[&1].offerId"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[]"
}
}
}
]
Response now:
[
{
"typeId": "5",
"offerId": "10"
},
{
"offerId": "9",
"typeId": "3"
},
{
"typeId": "2"
},
{
"offerId": "11"
},
{
"offerId": "14"
},
{
"offerId": "16"
}
]
Expected:
[
{
"typeId": "5",
"offerId": "10"
},
{
"typeId": "5",
"offerId": "9"
},
{
"typeId": "3",
"offerId": "11"
},
{
"typeId": "2",
"offerId": "14"
},
{
"typeId": "2",
"offerId": "16"
}
]
Please help to achieve as expected.
You can transfer "id": "[&4].[&2].typeId" key-value pair into the object tagged "offerings" key name as "#(2,type.id)": "[&3].[&1].typeid" in order to combine them as desired such like the below one
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"offerings": {
"*": {
"#(2,type.id)": "[&3].[&1].typeid",
"*": "[&3].[&1].offer&"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[]"
}
}
}
]
I have to send request body as org.hl7.fhir.r4.model.CoverageEligibilityRequest which is contained Patient, Practitioner, Organization as below. This API will return Bundle response. I am using Java and Generic client from Hapi Fire library. There is provision to pass search parameter but the here I am having multilevel hierarchy of resource and input is big than usual. Can any one help me to handle this request in FHIR API.
Request Body as below,
{
"resourceType": "CoverageEligibilityRequest",
"contained": [
{
"resourceType": "Patient",
"id": "1",
"name": [
{
"family": "abcFamily",
"given": [
"abcGiven"
]
}
],
"birthDate": "1962-08-06"
},
{
"resourceType": "Practitioner",
"id": "2",
"identifier": [
{
"type": {
"coding": [
{
"code": "NPI"
}
]
},
"value": "123456789"
}
],
"name": [
{
"family": "pqrFamily",
"given": [
"pqrGiven"
]
}
]
},
{
"resourceType": "Organization",
"id": "3",
"identifier": [
{
"value": "12345"
}
],
"name": ""
},
{
"resourceType": "Coverage",
"id": "3",
"status": "active",
"subscriberId": "",
"class": [
{
"type": {
"coding": [
{
"code": "group"
}
]
},
"value": ""
}
]
}
],
"extension": [
{
"url": "searchOption",
"valueString": "NameDateOfBirth"
}
],
"status": "active",
"purpose": [
"benefits"
],
"patient": {
"reference": "#1"
},
"provider": {
"reference": "#2"
},
"insurer": {
"reference": "#3"
}
}
I have the following json which get from endpoint,
{
"schemas": [
"urn:ietf:params:scim:api:messages:2.0:response",
"urn:scim:schemas:extension:customattrs:2.0:User"
],
"meta": {
"resourceType": "User",
"created": "2011-08-01T18:29:49.793Z",
"lastModified": "2011-08-01T18:29:49.793Z",
"version": "W/\"f250dd84f0671c3\""
},
"userName": "bjensen",
"phoneNumbers": [
{
"value": "555-555-8377",
"type": "work"
}
],
"emails": [
{
"value": "bjensen#example.com",
"type": "work",
"primary": true
}
],
"urn:scim:schemas:extension:customattrs:2.0:User": {
"userName": "bjensen",
"address": ""
}
}
please suggest me to parse the json along with schemas "urn:scim:schemas:extension:customattrs:2.0:User" into java object
I did some set of activities on json script. Need to add precondition on it.
how to use precondition on json script.
In precondition, i need to check the mysql db field. once flag as 'Y',
start execution else should be stop the execution.
You can use a ShellCommandPrecondition for this which will let you write a custom precondition.
{
"objects": [
{
"schedule": {
"ref": "DefaultSchedule"
},
"resourceRole": "DataPipelineDefaultResourceRole",
"role": "DataPipelineDefaultRole",
"name": "DefaultResource1",
"id": "ResourceId_dWoZ0",
"type": "Ec2Resource",
"terminateAfter": "1 Hour"
},
{
"name": "DefaultPrecondition1",
"id": "PreconditionId_yA2rV",
"type": "ShellCommandPrecondition",
"command": "<Script to check mysql field>"
},
{
"occurrences": "1",
"period": "1 Day",
"name": "RunOnce",
"id": "DefaultSchedule",
"type": "Schedule",
"startAt": "FIRST_ACTIVATION_DATE_TIME"
},
{
"failureAndRerunMode": "CASCADE",
"schedule": {
"ref": "DefaultSchedule"
},
"resourceRole": "DataPipelineDefaultResourceRole",
"role": "DataPipelineDefaultRole",
"pipelineLogUri": "s3://<mybucket>",
"scheduleType": "cron",
"name": "Default",
"id": "Default"
},
{
"schedule": {
"ref": "DefaultSchedule"
},
"name": "DefaultActivity1",
"runsOn": {
"ref": "ResourceId_dWoZ0"
},
"precondition": {
"ref": "PreconditionId_yA2rV"
},
"id": "ActivityId_gmQ0W",
"type": "ShellCommandActivity",
"command": "echo 'Hello world'"
}
],
"parameters": []
}