Host Engineering Forum
General Category => Do-more CPUs and Do-more Designer Software => Topic started by: RBPLC 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.
-
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.