JSON Utilities - JSON file written with invalid structure

mtho
2024-03-06
16 hours ago
  • mtho - 2024-03-06

    I'm using the JSON Utilities SL library to write configurations in my program to a file. I'm generating the JSON data using the builder function block and all appears to work correctly. When I write the jsondata to file, I'm finding that some of the JSON elements are not being written in the right location in the file. Rather than writing they keys under the parent object, they get written outside the root JSON object at the end of the file. If I then try to read the file back into the program, I get an invalid_structure error.

    I don't get any errors when populating the JSON data or when writing the file.

    I attached an example of the JSON writer output. The problems begin with key P200. Each P200 should go under MBR1 through MBR3. Among the rest of the keys, they are supposed to be under different parent objects. I am using default values for wsLineBreak and encoding.

     
  • brouwyka - 16 hours ago

    Hey there! I am currently running into the exact same issue (and have also posted to a similar post here: https://forge.codesys.com/forge/talk/Engineering/thread/c45929e2f1/#e27f).
    The JsonData object has all inexes & parent indexes in the way I expect, everything is correctly "linked".
    It purely seems that the writer is incorrectly parsing said JsonData, not based on parent & child index, but on something else that breaks it and puts things at the root, instead of the specified parent index.

    Did you ever manage to find a solution, or another way of achieving your JSON composing?

    I'm currently working on Codesys V3.5 SP19 Patch 7 with IIOT Libraries SL 1.13.0.0, specifically JSON Utilities SL 1.13.0.0 (to send requests to APIs with JSON bodies using Web Client SL 1.13.0.0).

     

    Last edit: brouwyka 16 hours ago

Log in to post a comment.