Forum Discussion

JiWon's avatar
JiWon
New Contributor II
6 years ago

Get Json output from Mapper snap

Hi, I am trying to get the output of the Mapper in my custom snap.
How should I write the code in my custom snap to get the Json object from the Mapper?

5 Replies

  • That’s correct:

    Map<String, Object> data = document.get(Map.class);
    
  • robin's avatar
    robin
    Former Employee

    @JiWon I don’t fully understand. If the next Snap is your custom Snap, the output document of the Mapper can be consumed via input views as per the developer documentation. In terms of the expression language, $ refers to the entire input document (which can be serialized/deserialized to/from JSON)

    • JiWon's avatar
      JiWon
      New Contributor II

      Hi Robin,
      Thanks for your reply.
      Yes, the Mapper connects to my custom snap in which I wanna get the data from the mapper. Can I use document.get(Map.class) to get the data from the Mapper?

  • DharaSP's avatar
    DharaSP
    New Contributor

    Were you able to successfully get the JSON output ?

    I am facing similar issue: Developing a custom SNAP that makes HTTP request and gets JSON response in return. The response is array of objects. In order to right it to document , currently it only shows up if I convert the response to string in following manner:

    Map<String, Object> data = new LinkedHashMap<>();
    data.put(“Response”, response);
    outputViews.write(documentUtility.newDocumentFor(document, data));

    But I’d like to instead preview the response in standard json format in outputview. Any idea how this can be achieved ? Any help would be appreciated . Thank you