You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Bruno client version v2.14.2 and trying to pass escaped string as variable to graphql variables and hitting script error.
Error : Pre-Request Script Error Expected ',' or '}' after property value in JSON at position 17 (line 2 column 16)
My pre-script has this
`let raw = "Joe, Alice";
let names = [];
if (Array.isArray(raw)) {
names = raw;
} else if (typeof raw === 'string') {
try {
const parsed = JSON.parse(raw);
names = Array.isArray(parsed) ? parsed : raw.split(',').map(s => s.trim()).filter(Boolean);
} catch {
names = raw.split(',').map(s => s.trim()).filter(Boolean);
}
}
// Build comparisons: ["==", {"F":"name"}, ""]
const nameComparisons = names.map(n => ["==", { F: "name" }, n]);
// Build the filter AST. Example result:
// ["||", ["==", {"F":"name"}, "Alice"], ["==", {"F":"name"}, "Bob"]]
const filterAst = ["||", ...nameComparisons];
// Stringify
const filterJson = JSON.stringify(filterAst);
const filterEscaped = filterJson.replace(/"/g, '\"').replace(/\n/g, '');
bru.setVar('filter', filterEscaped);
console.log('Filter : ' + filterEscaped);`
Accessing the filter as grapqhl request variable, API expects the filter value to be String
{
"filter": "{{filter}}"
}
I see the correct filter string from the console log
Filter : ["||",["==",{"F":"name"},"Joe"],["==",{"F":"name"},"Alice"]]
I'm not sure how to fix this pre-script error, is this Bruno issue or am I missing something ?
Beta Was this translation helpful? Give feedback.
All reactions