title: Parse JSON for Cyberpower UPS into InfluxDB/Grafana
body: <p>I'm trying to parse JSON from my Cyberpower UPS agent (for importing data into InfluxDB/Grafana). I'm able to parse everything I want with the exception of the battery state. Seen below, if the UPS is disconnected from utility power, the state is <strong>"Discharging"</strong>, but if it's connected, then the value contains a comma, <strong>"Normal, Fully Charged"</strong>.... I'm unable to find a way to parse the data knowing that the value may or may not have a comma in it. If the value is "Discharging", then it works fine, but because of the comma in <strong>"Normal, Fully Charged"</strong>, the grep result is <strong>"Normal</strong> (obviously missing the ending quotation).</p>
  
  <p>JSON for single value:</p>
  
  <pre><code>"battery":{"state":"Discharging",
  </code></pre>
  
  <p>JSON for value with comma and space:</p>
  
  <pre><code>"battery":{"state":"Normal, Fully Charged",
  </code></pre>
  
  <p>My curl/greb. Is it possible to do this to pull a value that may or may not have a comma in the value I want? If so, what am I doing wrong?</p>
  
  <pre><code>curl http://10.0.1.61:3052/agent/ppbe.js/init_status.js | grep -oP '(?&lt;="battery":{"state":)[^,]*' | head -1
  </code></pre>
  
  <p>Full .js page when discharging:
  </p>
  
  <pre><code>var ppbeJsObj = {
      "status": {
          "communicationAvaiable": true,
          "onlyPhaseArch": false,
          "utility": {
              "state": "Blackout",
              "stateWarning": true,
              "voltage": "0",
              "frequency": "60.00",
              "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": "120.0",
              "frequency": null,
              "load": 58,
              "watt": 522,
              "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": "Discharging",
              "stateWarning": true,
              "voltage": null,
              "capacity": 99,
              "runtimeFormat": 1,
              "runtimeFormatWarning": false,
              "runtimeHour": 0,
              "runtimeMinute": 20,
              "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,
              "originalHardwareFaultCode": "0x8080"
          },
          "modules": null,
          "deviceId": 0
      }
  };
  </code></pre>