Hi,
I have a local file called schema.json which contains all the schema of our endpoints. I am running a local http-server to serve this file. Postman will send a request to this server (through pre-request tab) and the response will be saved as an environment variable. All is well except in this file, I have a key called “pattern” and the value for this key will contain \
(slashes) because I am checking for a .
so i need to escape this in regular expression context.
eg. {
"endpoint1" : {
"type" : "object",
"properties" : {
"key1" : {
"type" : "string",
"pattern" : "^ABC\.ABC$"
}
}
},
//more endpoints here
}
when I call the service in the pre-request tab, I get an error in the console saying 'JSONError | Unexpected token '.' at 7:23 "pattern" : "^ABC\.ABC$" ^ '
Now if I put another slash in the file to escape the slash, the error will go away. But "pattern" : "^ABC\\.ABC$"
is different than "pattern" : "^ABC\.ABC$"
in regular expression point of view. And I want to avoid escaping of characters as its going to be a bit messy and confusing.
So question is, is there a way to somehow serve the contents of the files as it is (without the need to escape the slashes)?
Pre request script
const postRequest = {
url: ‘http://XX.XX.XX.XX:8080/test.json’,
method: ‘GET’
};
pm.sendRequest(postRequest, (error, response) => {
console.log(error ? error : response.json());
});
Postman console
Any help is appreciated.
Thanks.