Problem with spaces in json keys

Hi !

I have a problem with a jsonpath expression. I have the following JSON:

  "STATUS": [
      "STATUS": "S",
      "When": 1516116436,
      "Code": 11,
      "Msg": "Summary",
      "Description": "sgminer 5.6.2-l"
  "SUMMARY": [
      "Elapsed": 12040,
      "MHS av": 10140.4782,
      "MHS 5s": 10131.6409,
      "KHS av": 10140478,
      "KHS 5s": 10131641,
      "Found Blocks": 0,
      "Getworks": 841,
      "Accepted": 1479,
      "Rejected": 9,
      "Hardware Errors": 0,
      "Utility": 7.3705,
      "Discarded": 7674,
      "Stale": 0,
      "Get Failures": 0,
      "Local Work": 48659,
      "Remote Failures": 0,
      "Network Blocks": 806,
      "Total MH": 122090053.3249,
      "Work Utility": 35953.2862,
      "Difficulty Accepted": 7151707.47550726,
      "Difficulty Rejected": 49736.50586112,
      "Difficulty Stale": 0,
      "Best Share": 4552945.973721,
      "Device Hardware%": 0,
      "Device Rejected%": 0.6894,
      "Pool Rejected%": 0.6906,
      "Pool Stale%": 0,
      "Last getwork": 1516116435
  "id": 1

The path I want to extract is “$.SUMMARY[0].Hardware Errors”. The issue is that I get an exception with that:

2018-01-16 15:28:09.251 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while transforming ‘{
“STATUS”: “S”,
“When”: 1516116489,
“Code”: 11,
“Msg”: “Summary”,
“Description”: “sgminer 5.6.2-l”
“Elapsed”: 12095,
“MHS av”: 10138.718,
“MHS 5s”: 10145.7327,
“KHS av”: 10138718,
“KHS 5s”: 10145733,
“Found Blocks”: 0,
“Getworks”: 843,
“Accepted”: 1482,
“Rejected”: 9,
“Hardware Errors”: 0,
“Utility”: 7.3517,
“Discarded”: 7705,
“Stale”: 0,
“Get Failures”: 0,
“Local Work”: 48854,
“Remote Failures”: 0,
“Network Blocks”: 808,
“Total MH”: 122628961.3825,
“Work Utility”: 35865.5606,
“Difficulty Accepted”: 7167126.50611462,
“Difficulty Rejected”: 49736.50586112,
“Difficulty Stale”: 0,
“Best Share”: 4552945.973721,
“Device Hardware%”: 0,
“Device Rejected%”: 0.6879,
“Pool Rejected%”: 0.6892,
“Pool Stale%”: 0,
“Last getwork”: 1516116489
“id”: 1
}’ with ‘JSONPATH($.SUMMARY[0].‘Hardware Errors’)’ : ‘An error occurred while transforming JSON expression.’

Anyone knows how I could fix this as an online jsonpath tester showed the correct results ?

To @arnold and everyone who reads this. please use code fences and other formatting elements to make your postings bearable to read… -> Newlines are “control characters” so, no, you may not have a literal newline within your string.

Your json is malformed. Who/What generates it?

its generated by sgminer which is a mining software

I’ve opened an openHAB feature request to tolerate and remove newline characters in the jsonpath transformation. Still adding them is horribly wrong and you should open an issue over at

Source to reference:

thanks for this ! the issue is that the software is precompiled and I cannot really alter it on the machine that I want to integrate with so a fix in openhab would be great !

Open the issue first. Otherwise this will never be fixed.

Then here is your workaround:

  1. Store the string in a String Item
  2. Write a rule that triggers every time the String Item is updated
  3. Inside the rule remove all newline characters from the string
  4. Execute the jsonpath Transformation to extract the data you are looking for
  5. Store the data in a new Item

@arnold I may need to correct my anser from before.
Could you please try $.SUMMARY[0].['Hardware Errors']

1 Like

Thanks for your help ! That worked perfectly.