Hi @marting --
I’m thinking you might actually need to script this to where you’re mapping the expected string values (true/false) to integer values, such as --
function parseBooleanValue(value) {
if (value === 'true') {
return 1;
} else if (value === 'false') {
return 0;
} else {
return null; // or throw an error, depending on how you want to handle invalid values
}
}
Can’t fully vouch if this script will work specifically for you, but maybe something like this for some ideas --
// Define the URL of the JSON data source
def url = "https://example.com/status.json"
// Define the JSON Path expressions to extract the data
def expressions = [
"component1" : [
"param1&string" : "$.components[0].params[0].value",
"param2&bool" : "$.components[0].params[1].value"
],
"component2" : [
"param1&string" : "$.components[1].params[0].value",
"param2&bool" : "$.components[1].params[1].value"
]
]
// Define a function to parse boolean values
def parseBooleanValue(value) {
if (value === 'true') {
return 1;
} else if (value === 'false') {
return 0;
} else {
return null;
}
}
// Define the main data collection function
def collectData() {
// Fetch the JSON data from the URL
def response = get(url)
// Parse the JSON data
def json = new JsonSlurper().parseText(response.text)
// Loop through the components and parameters
for (componentName in expressions.keySet()) {
for (paramKey in expressions[componentName].keySet()) {
// Extract the value from the JSON data using the JSON Path expression
def value = JsonPath.read(json, expressions[componentName][paramKey])
// Convert boolean values to integers
if (paramKey.endsWith("&bool")) {
value = parseBooleanValue(value)
}
// Create a new datapoint with the value
def dpName = "${componentName}_${paramKey.replaceAll("&", "_")}"
def dp = new DataPoint(dpName, value)
addDataPoint(dp)
}
}
}
// Call the main data collection function
collectData()
In the above boilerplate, you would of course need to replace the url
variable with the URL of your JSON data source and modify the expressions
variable to match the structure of your JSON data source.
I hope this helps to stir some new ideas for you!