News:

  • June 25, 2026, 01:26:58 PM

Login with username, password and session length

Author Topic: Intended Behavior of JSONPARSE  (Read 7583 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Intended Behavior of JSONPARSE
« on: December 04, 2022, 08:18:11 PM »
What is the expected behavior of the JSONPARSE instruction in the event of a "missing" key/value pair?
Example:

I send the JSON message {"param1": 5, "param2": 10, "param3": 15} to TOPIC1. JSONPARSE parses this correctly and writes 5 to D0, 10 to D1 and 15 to D2. I send the message {"param1": 5, "param2": 10} to TOPIC1 and JSONPARSE writes 5 to D0, 10 to D1 and 0 to D2. Is the intended behavior to write a zero to the parameter associated with the missing key/value pair? To me it seems like the JSONPARSE should do nothing with the missing key/value pair and D2 should retain the last value of "param3", in this case 15.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6161
  • Yes Pinky, Do-more will control the world!
Re: Intended Behavior of JSONPARSE
« Reply #1 on: December 05, 2022, 10:21:09 AM »
What is the expected behavior of the JSONPARSE instruction in the event of a "missing" key/value pair?
Example:

I send the JSON message {"param1": 5, "param2": 10, "param3": 15} to TOPIC1. JSONPARSE parses this correctly and writes 5 to D0, 10 to D1 and 15 to D2. I send the message {"param1": 5, "param2": 10} to TOPIC1 and JSONPARSE writes 5 to D0, 10 to D1 and 0 to D2. Is the intended behavior to write a zero to the parameter associated with the missing key/value pair? To me it seems like the JSONPARSE should do nothing with the missing key/value pair and D2 should retain the last value of "param3", in this case 15.

It is by design that output values are cleared on a parse failure. One could argue that is or isn't the best behavior, but it is intentionally coded that way.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO