How to parse a local json/xml file in a Postman?

Hello,
I want to read lines from my local xml/json file in Pre-request script to add its value for my variables.
For example:
I have a file called OPC.xml, wanna attribute this file to a variable and find lines which have “name” in itself. E.g: “<Name)Qwerty (/Name>” I used ) because right formula makes it
invisible. Qwerty and other variables should be stored in one array.
How can I do this?
Thanks for any help.

HI @mkolomanski,

I’m afraid Postman can’t easily access local files directly because it runs in a sandbox :frowning:. However, there are a few workarounds as follows

  1. Postman can access data through API’s, so if you have the skills to create a local API (eg using Node.js & Express) then you can simply fetch the file using a request, store the data in a global, and use it in subsequent requests. (This isn’t as hard as you might think, I ran a workshop with complete novices to create a simple API - see slides 7-14)
  2. You can create a tool that formats your data into a csv or json file suitable to use with the collection runner, or Newman.
  3. You could write some code to inject your data into an environment or globals file prior to running it with Newman.

You’re probably going to have to write some code to get the data from your file into something that Postman can access, but that said, I’ve had to do this in the past and found it easier than I thought it might be (and I am not a dev by any estimation :cowboy_hat_face:)

Let us know which one you think might suit you best, and if you get stuck we can help you.

1 Like

Hello, I am very grateful for your complex response. But I already have dealt with it in other way.
Although parasing local files will be very useful. I am looking forward to have this option in Postman :slight_smile: Have a nice day!

1 Like