Forum Discussion

manjunathsinghs's avatar
manjunathsinghs
New Contributor II
2 years ago
Solved

How can i get the input data sent to JSON parser snap.

Hi, I have JSON parser snap in my pipeline and it is getting data from external resources. Sometimes the data parse is failing due to invalid input. But am not able to capture that input data and er...
  • koryknick's avatar
    4 months ago

    kumar25 - Here is another solution that does not use the Script snap.  I typically avoid the Script snap as it is notoriously difficult to debug and requires a different skill set that some developers may not yet possess.

    This solution uses a Gate snap to gather all the data into a single array.  Please be conscious of how large the file is that you're consuming as this will load the entire dataset into memory, which can't be avoided in this case since you want to pivot the entire dataset.

    Then in the Mapper, we're using the Object.keys() method to find the key names that were read in - basically just so we can loop through and grab all the values you want to pivot.  Then we're using the Array.map() method to change the value of each array element - this is where we're pivoting the records by re-creating the record from each set of column values.  Within the map() method, we're also using the Object.get() method to retrieve the value associated with the current field-name we're on.

    After the Mapper, we have a JSON Splitter snap to pull the array elements into individual documents, completing the pivot.

    Hope this helps!

  • koryknick's avatar
    4 months ago

    Sorry - here is the attachment.