How to cleanup a http return that icludes json, I just want the json

I have a UPS agent that returns a result that contains mostly the json results I want, but is pre-pended with some extra characters. I want to clean it so I can use jsonpath to populate my items.

The return from http is:

var ppbeJsObj={“status”:{“communicationAvaiable”:true,“onlyPhaseArch”:false,“utility”:{“state”:“Normal”,“stateWarning”:false,“voltage”:“118.0”,“frequency”:null,“voltages”:null,“currents”:null,“frequencies”:null,“powerFactors”:null},“bypass”:{“state”:“Normal”,“stateWarning”:false,“voltage”:null,“current”:null,“frequency”:null,“voltages”:null,“currents”:null,“frequencies”:null,“powerFactors”:null},“output”:{“state”:“Normal”,“stateWarning”:false,“voltage”:“118.0”,“frequency”:null,“load”:15,“watt”:76,“current”:null,“outputLoadWarning”:false,“outlet1”:null,“outlet2”:null,“activePower”:null,“apparentPower”:null,“reactivePower”:null,“voltages”:null,“currents”:null,“frequencies”:null,“powerFactors”:null,“loads”:null,“activePowers”:null,“apparentPowers”:null,“reactivePowers”:null,“emergencyOff”:null,“batteryExhausted”:null},“battery”:{“state”:“Normal, Fully Charged”,“stateWarning”:false,“voltage”:“20.3”,“capacity”:100,“runtimeFormat”:1,“runtimeFormatWarning”:false,“runtimeHour”:0,“runtimeMinute”:59,“chargetimeFormat”:null,“chargetimeHour”:null,“chargetimeMinute”:null,“temperatureCelsius”:null,“highVoltage”:null,“lowVoltage”:null,“highCurrent”:null,“lowCurrent”:null},“upsSystem”:{“state”:“Normal”,“stateWarning”:false,“temperatureCelsius”:null,“temperatureFahrenheit”:null,“maintenanceBreak”:null,“systemFaultDueBypass”:null,“systemFaultDueBypassFan”:null},“modules”:null,“deviceId”:0}};

Which starts with: var ppbeJsObj= And stops the http request from working.
(String Current_Power “Current Power [%s]” (Solar) {http=“<[http://172.16.0.56:3052/agent/ppbe.js/init_status.js:1000:JSONPATH($.status.battery.voltage)]”})

Is there a simple way to trim off the leading characters so this will work?

I think you have to use java-script-transformation-service with a little .js script. There you can use

input = input.replace("var ppbeJsObj=","");
JSON.parse(input).status.battery.voltage

As I don’t use .js myself I’m not sure if this is 100% correct :wink: