-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Milestone
Description
In the application we need to expose Json-parsed key:value objects for these two for convenience.
We can put something like this in a custom JsonParser passed to the callApiEndpoint:
let transformedInput = {}
if (response.evaluatedInputs && Array.isArray(response.evaluatedInputs)) {
transformedInput = response.evaluatedInputs.reduce(
(acc: any, input: any) => {
// Use inputName as key (lowercase for consistency)
const key = input.inputName.toLowerCase()
// Parse inputValue - it might be JSON-escaped or a plain value
let parsedValue = input.inputValue
try {
// Try to parse as JSON first (handles escaped strings and numbers)
parsedValue = JSON.parse(input.inputValue)
} catch {
// If JSON parsing fails, try to convert numbers
if (
typeof input.inputValue === 'string' &&
!isNaN(Number(input.inputValue))
) {
parsedValue = Number(input.inputValue)
} else {
// Keep as string if all parsing fails
parsedValue = input.inputValue
}
}
acc[key] = parsedValue
return acc
},
{}
)
}Reactions are currently unavailable