Home > Enterprise >  After REST API call ,i have key/value pair in the below format ,I Need to extract just the specific
After REST API call ,i have key/value pair in the below format ,I Need to extract just the specific

Time:09-16

enter image description here Option 1 :if i use the TALEND job i get the JSON results stored with backslashes in the JSON file for some reason(which is unparseable)

{"read":[{"Body":"{\"items\":[{\"executionId\":\"a0613a31-d16d-4c4d-9279-4564a86cdd44\",\"startTimestamp\":\"2021-09-15T22:30:26.854Z\",\"triggerTimestamp\":\"2021-09-15T22:30:27.209Z\",\"userId\":\"user1\",\"status\":\"dispatching\",\"runtime{\"type\":\"REMOTE_ENGINE_CLUSTER\"},\"executionStatus\":\"DISPATCHING_FLOW\"},{\"executionId\":\"49a56eb1-f3c7-4f26-9554-8fa88acde38b\",\"startTimestamp\":\"2021-09-15T22:29:15.999Z\",\"triggerTimestamp\":\"2021-09-15T22:29:16.447Z\",\"userId\":\"user1\",\"executionType\":\"MANUAL\",\"status\":\"dispatching\",\"runtime\":{\"type\":\"REMOTE_ENGINE_CLUSTER\"},\"executionStatus\":\"DISPATCHING_FLOW\"}],\"limit\":100,\"offset\":0,\"total\":2}","ERROR_CODE":null}]}

Option 2:Using the WEB URL: After REST API call,i have the JSON results like:

BODY:context.statusbody

{
    "items": [{
            "executionId": "4f679c12-d8d7-4dd7-89d5-507a94503988",
            "startTimestamp": "2021-09-14T19:05:01.854Z",
            "triggerTimestamp": "2021-09-14T19:05:02.385Z",
            "userId": "user1",
            "taskId": "60b7f6d31c6e394de0163d35",
            "status": "dispatching",
            "runtime": {
                "type": "REMOTE_ENGINE_CLUSTER"
            },
            "executionStatus": "DISPATCHING_FLOW"
        },
        {
            "executionId": "4f40b04c-1ac1-42ea-9a36-7c25b1b17fe8",
            "startTimestamp": "2021-09-14T19:00:24.769Z",
            "triggerTimestamp": "2021-09-14T19:00:25.122Z",
            "userId": "user1",
            "taskId": "60b7f6d31c6e394de0163d35",
            "executionType": "SCHEDULED",
            "status": "dispatching",
            "runtime": {
                "type": "REMOTE_ENGINE_CLUSTER"
            },
            "executionStatus": "DISPATCHING_FLOW"
        }
    ],
    "limit": 100,
    "offset": 0,
    "total": 2
}

From this i just need to extract the executionID and triggerTimestamp for each iteration and store in a global variable

How to extract the option 1 results into option 2 readable format that i could use to store in a JSON file and read/process from thereon?

CodePudding user response:

Okey , Json i Used for your case to do your requirement :

Note That your Json is not Valid

{
    "items": [{
        "executionId": "6e5fa777-9ede-42b9-b862-03b4b1b12375",
        "startTimestamp": "2021-09-15T05:59:40.599Z",
        "triggerTimestamp": "2021-09-15T05:59:41.006Z",
        "userId": "user"
    }],
    "limit ": 100,
    "offset ": 0,
    "total ": 2
}

Without knowing your job design i just got the output that is posted right here .

My job design is as such :

enter image description here

Important !: your tFileInputJson should be like this to get the 2 fields

Same configuration if your want to used tExtractJSONFields .

enter image description here

to Stock your Global Variables :

enter image description here

to get the globalVariables easy way is to use tfixedFlowInput :

enter image description here

Output :

enter image description here

CodePudding user response:

@sarah Based on your valid JSON you added in your edit .

i suggest you to add after tRest to add tExtractJSONFields component paremetred as such :

enter image description here

Job Design should be in first test :

tRest -> tExtractJSONFields -> tLogRow .

If extraction is good . Second test you have to see my previous my first answer to get global Variables .

  • Related