Skip to content

Jsonata usage in Postman #739

@radhakrishnan-chandarasikharan-kr

Description

I'm trying to use jsonata script as part of Postman.
Using the snippet below I have been able to get the visualizer to render the output successfully. However, not all scripts are working in Postman. Simple transforms seem to work. When I have complex transforms it bombs. The same works on the exerciser.

Any hints on what I can dig into further? Is the difference in the javascript engine likely to cause this issue? How can I investigate that?

jsonata_library = pm.collectionVariables.get('jsonata_library');

// Invoke an anonymous function to get access to the library methods
(new Function(jsonata_library))();

doc = pm.response.json();
scr = `
<<< JSONATA SCRIPT >>>
`;


await jsonata(scr).evaluate(doc, {}, (error, result) => {
  if(error) {
    console.error(error);
    return;
  }
  console.log("Finished with", result);
  out = result;
});

console.log("transformed");

template = `
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
</head>
<body>
<pre><code class="json">{{response}}</code></pre>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
</body>
</html>
`;
pm.visualizer.set(template, {
    // Pass the response body parsed as JSON as `data`
    response: JSON.stringify(out,null,2)
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions