- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
What Jolt transform will extract fields from the provided JSON, and copy them to the top of the json structure
- Labels:
-
Apache NiFi
Created ‎10-18-2018 12:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have the following JSON. I'd like to transform the JSON by extracting the "issued" field ("issued":"2018-10-17T20:16:00.000Z") and outputting a new JSON that preserves the existing JSON, but appends a new JSON that would contain a new property
"issued_datetime":"2018-10-17T20:16:00.000Z". I'd also like to extract the effectiveStart and effectiveEnd and add them to the top level of the output JSON as well. So the output JSON would be the input JSON, with 3 properties added to it (replicas of issued, effectiveStart, effectiveEnd).
Could someone please help me with the JOLT transform that would facilitate this.
Input JSON:
{ "textNOTAM": { "NOTAM": { "id": "NOTAM_1_51125176", "number": 108, "year": 2018, "type": "N", "issued": "2018-10-17T20:16:00.000Z", "affectedFIR": "ZOA", "minimumFL": "000", "maximumFL": 999, "radius": 5, "location": "SCK", "effectiveStart": 201810201100, "effectiveEnd": 201811032000, "schedule": "SAT SUN", "text": "SVC PCL RWY 11L/29R REDL OUT OF SERVICE SAT SUN 1100-2000", "translation": [ { "NOTAMTranslation": { "id": "NT01_51125176", "type": "LOCAL_FORMAT", "simpleText": "!SCK 10/108 SCK SVC PCL RWY 11L/29R REDL OUT OF SERVICE SAT SUN 1100-2000 1810201100-1811032000" } }, { "NOTAMTranslation": { "id": "NT02_51125176", "type": "OTHER:ICAO", "formattedText": { "div": "10/108 NOTAMR \r\nQ) ZOA/QLEXX/IV/NBO/A/000/999/3753N12114W005 \r\nA) KSCK \r\nB) 1810201100 \r\nC) 1811032000 \r\n D) SAT SUN 1100-2000 \r\n\r\nE) \r\nSVC PCL RWY 11L/29R REDL PCL OUT OF SERVICE" } } } ] } } } <br>
Desired Output JSON:
{ "issued":"2018-10-17T20:16:00.000Z", "effectiveStart":201810201100, "effectiveEnd":201811032000, { "textNOTAM": { "NOTAM": { "id": "NOTAM_1_51125176", "number": 108, "year": 2018, "type": "N", "issued": "2018-10-17T20:16:00.000Z", "affectedFIR": "ZOA", "minimumFL": "000", "maximumFL": 999, "radius": 5, "location": "SCK", "effectiveStart": 201810201100, "effectiveEnd": 201811032000, "schedule": "SAT SUN", "text": "SVC PCL RWY 11L/29R REDL OUT OF SERVICE SAT SUN 1100-2000", "translation": [ { "NOTAMTranslation": { "id": "NT01_51125176", "type": "LOCAL_FORMAT", "simpleText": "!SCK 10/108 SCK SVC PCL RWY 11L/29R REDL OUT OF SERVICE SAT SUN 1100-2000 1810201100-1811032000" } }, { "NOTAMTranslation": { "id": "NT02_51125176", "type": "OTHER:ICAO", "formattedText": { "div": "10/108 NOTAMR \r\nQ) ZOA/QLEXX/IV/NBO/A/000/999/3753N12114W005 \r\nA) KSCK \r\nB) 1810201100 \r\nC) 1811032000 \r\n D) SAT SUN 1100-2000 \r\n\r\nE) \r\nSVC PCL RWY 11L/29R REDL PCL OUT OF SERVICE" } } } ] } } } }
Created ‎10-19-2018 06:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@@David Sargrad,
you can use this specification,
[ { "operation": "shift", "spec": { "textNOTAM": { "NOTAM": { "issued": "issued", "effectiveStart": "effectiveStart", "effectiveEnd": "effectiveEnd", "@": "&2.&" } } } } ]
Created ‎10-18-2018 03:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I'm getting close with the following spec:
[ { "operation": "shift", "spec": { "textNOTAM": { "NOTAM": { // simple match. Put the value '4' in the output under the "Rating" field "issued": "&0", "affectedFIR": "&0" } } } }, { "operation": "default", "spec": {} }] The output has extracted fields.. but it does not also contain the original { "issued" : "2018-10-17T20:16:00.000Z", "affectedFIR" : "ZOA" }
Created ‎10-19-2018 06:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@@David Sargrad,
you can use this specification,
[ { "operation": "shift", "spec": { "textNOTAM": { "NOTAM": { "issued": "issued", "effectiveStart": "effectiveStart", "effectiveEnd": "effectiveEnd", "@": "&2.&" } } } } ]
Created ‎10-19-2018 10:14 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank You. I am brand new to jolt and am finding it a bit of a confusing syntax. I will get there however. It seems powerful. Do you have a description of what the following is doing:
"@":"&2.&"
Created ‎10-19-2018 11:26 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@David Sargard,
"@" copies whatever is present at the current level, and copies it to "&2.&"
Here &2 means go up two levels and grab the key, and & means go up one level and grab the key.
i.e., &2 will return textNOTAM and & will return NOTAM, so &2.& will place whatever value you get at the following jsonPath: textNOTAM.NOTAM
