<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: JoltTransformJson Spec in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192328#M71053</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/11035/sanazjanbakhsh.html" nodeid="11035"&gt;@Sanaz Janbakhsh&lt;/A&gt;
&lt;/P&gt;&lt;P&gt;Can you once try the below Spec&lt;/P&gt;&lt;PRE&gt; [{ "operation": "shift",
  "spec": {
    "payloadMetaData": {
      "rawPayload": "rawPayload",
      "fcount": "fcount",
      "fport": "fport",
      "applicationMetaData": {
        "id": {
          "entityType": "entityType",
          "id": "id"
        },
        "customerId": {
          "entityType": "entityTypeCustomer",
          "id": "idCustomer"
        }
      },
      "gatewayMetaDataList": {
        "*": {  //* means if you are having more than 1 message in array then it results array of mac addresses in it.
          "mac": "mac"
        }
      },
      "deviceMetaData": {
        "id": {
          "entityType": "entityTypeDevice",
          "id": "DeviceId"
        },
        "name": "DeviceName",
        "deviceClass": "deviceClass",
        "deviceEUI": "deviceEUI",
        "appEUI": "appEUI"
      }
    },
    "payload": "payload"
  }
}]&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;input:-&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;{
  "payloadMetaData": {
    "applicationMetaData": {
      "id": {
        "entityType": "APPLICATION",
        "id": "7d11abf0-aa82-11e7-afd4-63e5a28ad7fa"
      },
      "customerId": {
        "entityType": "CUSTOMER",
        "id": "a84ab1a0-aa81-11e7-afd4-63e5a28ad7fa"
      },
      "subCustomerId": null,
      "name": "TekTelic-Industrial"
    },
    "gatewayMetaDataList": [
      {
        "id": {
          "entityType": "GATEWAY",
          "id": "e5ca6840-aa81-11e7-afd4-63e5a28ad7fa"
        },
        "name": "ColinsGateway",
        "mac": "647FDAFFFE00417C",
        "latitude": 51.04697912502887,
        "longitude": -114.06121730804443,
        "altitude": null,
        "rxInfo": {
          "channel": 2,
          "codeRate": "4/5",
          "crcStatus": 1,
          "dataRate": {
            "modulation": "LORA",
            "spreadFactor": 7,
            "bandwidth": 125
          },
          "frequency": 902700000,
          "loRaSNR": 6.8,
          "mac": "647fdafffe00417c",
          "rfChain": 0,
          "rssi": -51,
          "size": 21,
          "time": "2017-11-01T21:51:27Z",
          "timestamp": 1400148651,
          "rsig": null
        }
      }
    ],
    "deviceMetaData": {
      "id": {
        "entityType": "DEVICE",
        "id": "61348ab0-ada2-11e7-ac06-63e5a28ad7fa"
      },
      "name": "TekTelic-Industrial-0017",
      "deviceClass": "CLASS_A",
      "deviceEUI": "647FDA0000000155",
      "appEUI": "647FDA8000000155"
    },
    "fcount": 3706,
    "fport": 10
  }
}
&lt;/PRE&gt;
&lt;STRONG&gt;Output:-&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;PRE&gt;&lt;STRONG&gt;{
  "fcount" : 3706,
  "fport" : 10,
  "entityType" : "APPLICATION",
  "id" : "7d11abf0-aa82-11e7-afd4-63e5a28ad7fa",
  "entityTypeCustomer" : "CUSTOMER",
  "idCustomer" : "a84ab1a0-aa81-11e7-afd4-63e5a28ad7fa",
  "mac" : "647FDAFFFE00417C",
  "entityTypeDevice" : "DEVICE",
  "DeviceId" : "61348ab0-ada2-11e7-ac06-63e5a28ad7fa",
  "DeviceName" : "TekTelic-Industrial-0017",
  "deviceClass" : "CLASS_A",
  "deviceEUI" : "647FDA0000000155",
  "appEUI" : "647FDA8000000155"
}&lt;/STRONG&gt;&lt;/PRE&gt;

&lt;P style=""&gt;in addition if you want to flatten out all the elements of array then &lt;STRONG&gt;&lt;/STRONG&gt;extract all the json message contents by using eval json path processor with Destination as flowfile-attribute, then use split json processor with &lt;/P&gt;&lt;PRE&gt;JsonPath Expression as $.gatewayMetaDataList &lt;/PRE&gt;&lt;P&gt;then use&lt;STRONG&gt; jolt transform &lt;/STRONG&gt;with below spec&lt;/P&gt;&lt;PRE&gt;[{
  "operation": "shift",
  "spec": {
    "*": {
      "*": "id-&amp;amp;",
      "id": {
        "*": "&amp;amp;"
      },
      "rxInfo": {
        "*": "rxInfo-&amp;amp;",
        "dataRate": {
          "*": "dataRate-&amp;amp;"
        }
      }
    }
  }
}]&lt;/PRE&gt;&lt;P&gt;Right now you are doing flattening out json array elements then use attributes to json processor &lt;/P&gt;&lt;P&gt;and keep all the attributes that you have extracted, now this processor will create new json message which is flattened out with each array elements in it.&lt;BR /&gt;(or)&lt;BR /&gt;if you want to add all array elements to respective keys then use below spec&lt;/P&gt;&lt;PRE&gt; [{
  "operation": "shift",
  "spec": {
    "payloadMetaData": {
      "gatewayMetaDataList": {
        "*": {
          "*": "id-&amp;amp;",
          "id": {
            "*": "&amp;amp;"
          },
          "rxInfo": {
            "*": "rxInfo-&amp;amp;",
            "dataRate": {
              "*": "dataRate-&amp;amp;"
            }
          }
        }
      }
    }
  }
}&lt;/PRE&gt;</description>
    <pubDate>Fri, 10 Nov 2017 22:53:19 GMT</pubDate>
    <dc:creator>Shu_ashu</dc:creator>
    <dc:date>2017-11-10T22:53:19Z</dc:date>
    <item>
      <title>JoltTransformJson Spec</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192327#M71052</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;I need to flatten the following input,&lt;/P&gt;</description>
      <pubDate>Thu, 09 Nov 2017 14:58:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192327#M71052</guid>
      <dc:creator>Sanaz_janbakhsh</dc:creator>
      <dc:date>2017-11-09T14:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: JoltTransformJson Spec</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192328#M71053</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/11035/sanazjanbakhsh.html" nodeid="11035"&gt;@Sanaz Janbakhsh&lt;/A&gt;
&lt;/P&gt;&lt;P&gt;Can you once try the below Spec&lt;/P&gt;&lt;PRE&gt; [{ "operation": "shift",
  "spec": {
    "payloadMetaData": {
      "rawPayload": "rawPayload",
      "fcount": "fcount",
      "fport": "fport",
      "applicationMetaData": {
        "id": {
          "entityType": "entityType",
          "id": "id"
        },
        "customerId": {
          "entityType": "entityTypeCustomer",
          "id": "idCustomer"
        }
      },
      "gatewayMetaDataList": {
        "*": {  //* means if you are having more than 1 message in array then it results array of mac addresses in it.
          "mac": "mac"
        }
      },
      "deviceMetaData": {
        "id": {
          "entityType": "entityTypeDevice",
          "id": "DeviceId"
        },
        "name": "DeviceName",
        "deviceClass": "deviceClass",
        "deviceEUI": "deviceEUI",
        "appEUI": "appEUI"
      }
    },
    "payload": "payload"
  }
}]&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;input:-&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;{
  "payloadMetaData": {
    "applicationMetaData": {
      "id": {
        "entityType": "APPLICATION",
        "id": "7d11abf0-aa82-11e7-afd4-63e5a28ad7fa"
      },
      "customerId": {
        "entityType": "CUSTOMER",
        "id": "a84ab1a0-aa81-11e7-afd4-63e5a28ad7fa"
      },
      "subCustomerId": null,
      "name": "TekTelic-Industrial"
    },
    "gatewayMetaDataList": [
      {
        "id": {
          "entityType": "GATEWAY",
          "id": "e5ca6840-aa81-11e7-afd4-63e5a28ad7fa"
        },
        "name": "ColinsGateway",
        "mac": "647FDAFFFE00417C",
        "latitude": 51.04697912502887,
        "longitude": -114.06121730804443,
        "altitude": null,
        "rxInfo": {
          "channel": 2,
          "codeRate": "4/5",
          "crcStatus": 1,
          "dataRate": {
            "modulation": "LORA",
            "spreadFactor": 7,
            "bandwidth": 125
          },
          "frequency": 902700000,
          "loRaSNR": 6.8,
          "mac": "647fdafffe00417c",
          "rfChain": 0,
          "rssi": -51,
          "size": 21,
          "time": "2017-11-01T21:51:27Z",
          "timestamp": 1400148651,
          "rsig": null
        }
      }
    ],
    "deviceMetaData": {
      "id": {
        "entityType": "DEVICE",
        "id": "61348ab0-ada2-11e7-ac06-63e5a28ad7fa"
      },
      "name": "TekTelic-Industrial-0017",
      "deviceClass": "CLASS_A",
      "deviceEUI": "647FDA0000000155",
      "appEUI": "647FDA8000000155"
    },
    "fcount": 3706,
    "fport": 10
  }
}
&lt;/PRE&gt;
&lt;STRONG&gt;Output:-&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;PRE&gt;&lt;STRONG&gt;{
  "fcount" : 3706,
  "fport" : 10,
  "entityType" : "APPLICATION",
  "id" : "7d11abf0-aa82-11e7-afd4-63e5a28ad7fa",
  "entityTypeCustomer" : "CUSTOMER",
  "idCustomer" : "a84ab1a0-aa81-11e7-afd4-63e5a28ad7fa",
  "mac" : "647FDAFFFE00417C",
  "entityTypeDevice" : "DEVICE",
  "DeviceId" : "61348ab0-ada2-11e7-ac06-63e5a28ad7fa",
  "DeviceName" : "TekTelic-Industrial-0017",
  "deviceClass" : "CLASS_A",
  "deviceEUI" : "647FDA0000000155",
  "appEUI" : "647FDA8000000155"
}&lt;/STRONG&gt;&lt;/PRE&gt;

&lt;P style=""&gt;in addition if you want to flatten out all the elements of array then &lt;STRONG&gt;&lt;/STRONG&gt;extract all the json message contents by using eval json path processor with Destination as flowfile-attribute, then use split json processor with &lt;/P&gt;&lt;PRE&gt;JsonPath Expression as $.gatewayMetaDataList &lt;/PRE&gt;&lt;P&gt;then use&lt;STRONG&gt; jolt transform &lt;/STRONG&gt;with below spec&lt;/P&gt;&lt;PRE&gt;[{
  "operation": "shift",
  "spec": {
    "*": {
      "*": "id-&amp;amp;",
      "id": {
        "*": "&amp;amp;"
      },
      "rxInfo": {
        "*": "rxInfo-&amp;amp;",
        "dataRate": {
          "*": "dataRate-&amp;amp;"
        }
      }
    }
  }
}]&lt;/PRE&gt;&lt;P&gt;Right now you are doing flattening out json array elements then use attributes to json processor &lt;/P&gt;&lt;P&gt;and keep all the attributes that you have extracted, now this processor will create new json message which is flattened out with each array elements in it.&lt;BR /&gt;(or)&lt;BR /&gt;if you want to add all array elements to respective keys then use below spec&lt;/P&gt;&lt;PRE&gt; [{
  "operation": "shift",
  "spec": {
    "payloadMetaData": {
      "gatewayMetaDataList": {
        "*": {
          "*": "id-&amp;amp;",
          "id": {
            "*": "&amp;amp;"
          },
          "rxInfo": {
            "*": "rxInfo-&amp;amp;",
            "dataRate": {
              "*": "dataRate-&amp;amp;"
            }
          }
        }
      }
    }
  }
}&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Nov 2017 22:53:19 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192328#M71053</guid>
      <dc:creator>Shu_ashu</dc:creator>
      <dc:date>2017-11-10T22:53:19Z</dc:date>
    </item>
    <item>
      <title>Re: JoltTransformJson Spec</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192329#M71054</link>
      <description>&lt;P&gt;Hi Shu,&lt;/P&gt;&lt;P&gt;Thanks for your advise. I think i missed one of the important step in your instruction. &lt;/P&gt;&lt;P&gt;You are right, i want to flatten all the elements including elements of array. &lt;/P&gt;&lt;P&gt;I decided to take two different options and for both i was not successful :&lt;/P&gt;&lt;P&gt;1- I tried to flattened all the attribute names which are not pert of array and so i used the attached Jolt Spec&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/43574-1.txt"&gt;1.txt&lt;/A&gt; but then the result doesn't include gatewayMetaDataList and so i use &lt;STRONG&gt;&lt;U&gt;EvaluateJsonPath for the array in the next step&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2- I used "evaluateJsonPath" with destination of flowfile-attribute and then split json processor with JsonPathExpressionas $.gatewayMetaDataList" but i get the attached error. &lt;A href="https://community.cloudera.com/legacyfs/online/attachments/43575-untitled.png"&gt;untitled.png&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Could you please advise which step i did wrong?&lt;/P&gt;&lt;P&gt;Thanks, SJ&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 14:18:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192329#M71054</guid>
      <dc:creator>Sanaz_janbakhsh</dc:creator>
      <dc:date>2017-11-13T14:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: JoltTransformJson Spec</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192330#M71055</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/11035/sanazjanbakhsh.html" nodeid="11035"&gt;@Sanaz Janbakhsh&lt;/A&gt;,&lt;BR /&gt;Use the below spec you can get gatewayMetaDataList array as is.&lt;/P&gt;&lt;PRE&gt;[{
  "operation": "shift",
  "spec": {
    "payloadMetaData": {
      "*": "&amp;amp;",
      "applicationMetaData": {
        "id": {
          "entityType": "entityType",
          "id": "ApplicationId"
        },
        "customerId": {
          "entityType": "entityTypeCustomer",
          "id": "CustomerId"
        },
        "subCustomerId": "subCustomerId",
        "name": "SubCustomerName"
      },
      "deviceMetaData": {
        "id": {
          "entityType": "entityTypeDevice",
          "id": "DeviceId"
        },
        "name": "DeviceName",
        "deviceClass": "deviceClass",
        "deviceEUI": "deviceEUI",
        "appEUI": "appEUI"
      },
      "rawPayload": "rawPayload",
      "fcount": "fcount",
      "fport": "fport"
    },
    "payload": "payload"
  }
}]&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Flow:-&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;1.JoltTransform //flatten all the message except gatewayMetaDataList array&lt;BR /&gt;2.EvaluateJsonPath //to extract all the content and keep it as attributes to the flowfile and change &lt;B&gt;Destination Property&lt;/B&gt; to &lt;B&gt;Flowfile-Attribute&lt;/B&gt;.&lt;BR /&gt;3.SplitJson //split the json on gatewayMetaDataList array &lt;BR /&gt;4.JoltTransform //flatten gatewayMetaDataList array &lt;BR /&gt;5.EvaluateJsonPath //to extract all the content and keep it as attributes to the flowfile and change &lt;B&gt;Destination Property&lt;/B&gt; to &lt;B&gt;Flowfile-Attribute&lt;/B&gt;.&lt;BR /&gt;6.AttributesToJson //keep all the attribute names and change &lt;STRONG&gt;Destination Property&lt;/STRONG&gt; to &lt;STRONG&gt;Flowfile-Content&lt;/STRONG&gt;.&lt;/PRE&gt;&lt;P&gt;You can use the below xml for reference and change the &lt;STRONG&gt;eval json path&lt;/STRONG&gt; as per your requirements.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.cloudera.com/legacyfs/online/attachments/42564-jolt-11-13.xml"&gt;jolt-11-13.xml&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 23:37:55 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192330#M71055</guid>
      <dc:creator>Shu_ashu</dc:creator>
      <dc:date>2017-11-13T23:37:55Z</dc:date>
    </item>
    <item>
      <title>Re: JoltTransformJson Spec</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192331#M71056</link>
      <description>&lt;P&gt;Excellent help. Thanks alot. &lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 13:52:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/JoltTransformJson-Spec/m-p/192331#M71056</guid>
      <dc:creator>Sanaz_janbakhsh</dc:creator>
      <dc:date>2017-11-14T13:52:41Z</dc:date>
    </item>
  </channel>
</rss>

