{"id":45897702,"url":"https://github.com/simatic-ax/json","last_synced_at":"2026-02-27T21:34:53.997Z","repository":{"id":65724373,"uuid":"454954023","full_name":"simatic-ax/json","owner":"simatic-ax","description":"Library to serialize a JSON object model into a array of character and parse a array of character for JSON elements","archived":false,"fork":false,"pushed_at":"2025-11-17T08:49:04.000Z","size":345,"stargazers_count":3,"open_issues_count":5,"forks_count":2,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-11-17T10:23:01.768Z","etag":null,"topics":["iec-st","library","siemens","simatic-ax"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simatic-ax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-02-02T22:18:29.000Z","updated_at":"2025-11-17T08:46:14.000Z","dependencies_parsed_at":"2023-02-19T10:35:18.137Z","dependency_job_id":"84bd89b1-5a2c-480f-90e6-9dd72a6ff5c8","html_url":"https://github.com/simatic-ax/json","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/simatic-ax/json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simatic-ax%2Fjson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simatic-ax%2Fjson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simatic-ax%2Fjson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simatic-ax%2Fjson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simatic-ax","download_url":"https://codeload.github.com/simatic-ax/json/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simatic-ax%2Fjson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29915345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-27T19:37:42.220Z","status":"ssl_error","status_checked_at":"2026-02-27T19:37:41.463Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iec-st","library","siemens","simatic-ax"],"created_at":"2026-02-27T21:34:53.173Z","updated_at":"2026-02-27T21:34:53.990Z","avatar_url":"https://github.com/simatic-ax.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# JSON Library\r\n\r\n## Description\r\n\r\nThis Library will provides the possibility to serialize and deserialize JSON Files.\r\n\r\n## Install this package\r\n\r\nEnter:\r\n\r\n```cli\r\napax add @simatic-ax/json\r\n```\r\n\r\n\u003e to install this package you need to login into the GitHub registry. You'll find more information [here](https://github.com/simatic-ax/.github/blob/main/docs/personalaccesstoken.md)\r\n\r\n## Namespace\r\n\r\n```sh\r\nSimatic.Ax.Json;\r\n```\r\n\r\n## Deserializing\r\n\r\nUse the _Deserializer_ class to deserialize JSON documents and parse values from the document.\r\n\r\n### Restrictions\r\n\r\nIn the current version we have several restrictions regarding the handling of JSON files.\r\n\r\n1. The JSON File must be in the form of a ARRAY [] OF CHAR. Read more in the _Workflow_ part.\r\n\r\n2. A valid JSON file ist expected, since there is no validation.\r\n\r\n3. ### Forbidden characters in keys and values\r\n\r\n    |||\r\n    |-|-|\r\n    |,| comma|\r\n    |\"| quotation marks|\r\n    |:| colon|\r\n    |[ ] | square brackets|\r\n    |{ } | brackets|\r\n    |||\r\n\r\n4. The following Datatypes can be parsed:\r\n    |||\r\n    |-|-|\r\n    | STRING |\r\n    | SINT |\r\n    | INT |\r\n    | DINT |\r\n    | LINT |\r\n    | USINT |\r\n    | UINT |\r\n    | UDINT |\r\n    | ULINT |\r\n    |||\r\n\r\n## Workflow\r\n\r\n### Pre-requirements\r\n\r\n1. You need to use the library _Simatic.Ax.Conversion_ and _Simatic.Ax.Json_;\r\n2. The deserializer currently expects an _ARRAY[0..999] OF CHAR_ as a buffer. If your JSON File is a STRING you can use the _Simatic.Ax.Conversion_ as shown in the example below.\r\n3. Finally you must set the buffer for the deserializer with the _SetBuffer_ method. The buffer is expected as a reference.\r\n\r\n### Get values\r\n\r\nUse the _TryParse_ method to get values that match your provided STRING key . If you want to get values of nested elements you must instead provide a ARRAY [X] OF STRING, with a key for each nested layer.\r\n\r\nThe datatype _TryParse_ will return depends on the datatype of the value you provide.\r\n\r\nIf the parsing was succesfull, _TryParse_ returns TRUE, if either the key could not be found or the datatype could not be parsed it returns FALSE.\r\nIn the case of an unsucesfull parsing, the output value will be '' in case of STRING and 0 in case of any number.\r\n\r\n```iec-st\r\nUSING Simatic.Ax.Json;\r\nUSING Simatic.Ax.Conversion;\r\n\r\n### Code Example\r\n\r\n[...]\r\nVAR PUBLIC\r\n    //pre requirements\r\n    deserializer : Deserializer;\r\n    buffer : ARRAY[0..999] OF CHAR;\r\n    JSON_File: STRING := '{ \"key 1\" : 123, 'key 2' : {'nestedkey 1' : \"456\", 'nestedkey 2': {'nestedInNested': 789}}}'; //example of your JSON file\r\n    \r\n    //optional conversion information\r\n    arrayLength:= DINT;\r\n\r\n    //deserializing\r\n    parsingWasSuccessfull: BOOL;\r\n\r\n    key1: STRING := 'key 1'; //example for a single key\r\n    value1: INT;\r\n\r\n    keyArray1: ARRAY [0..1] OF STRING:= ['key 2', 'nestedkey 1']; //example for getting values of a nested element\r\n    value2: STRING; //change the datatype to parse different datatypes, e.g. INT\r\n\r\n    keyArray2: ARRAY [0..1] OF STRING:= ['key 2', 'nestedkey 2', 'nestedInNested'];\r\n    value3: DINT;\r\n\r\nEND_VAR\r\n\r\narrayLength := Strings.ToArray(str := JSON_File, arr := buffer); //Step 2: converts your JSON file string to the required _Array [0.999] OF CHAR_ format\r\ndeserializer.SetBuffer(REF(buffer));\r\n\r\n// parsingWasSuccessfull is true, value1 is 123\r\nparsingWasSuccessfull:= TryParse(key1, value1);\r\n\r\n// parsingWasSuccessfull is true, value2 is 456\r\nparsingWasSuccessfull:= TryParse(keyArray1, value2);\r\n\r\n// parsingWasSuccessfull is true, value3 is 789\r\nparsingWasSuccessfull:= TryParse(keyArray2, value3);\r\n\r\n// parsingWasSuccessfull is false, value1 is 0\r\nparsingWasSuccessfull:= TryParse('not a key', value3);\r\n\r\n[...]\r\n```\r\n\r\n### Methods\r\n\r\n|||\r\n|-|-|\r\n|SetBuffer(REF_TO ARRAY[0..999] OF CHAR);| Provides the JSON file to the deserializer|\r\n|TryParse(input: key (STRING), output: value) : BOOL| Returns false when parsing not succesfull and provides the value. The method is overloaded and accepts different data types. |\r\n|TryParse(input: key(ARRAY OF STRING), output: value) : BOOL| Returns false when parsing not succesfull and provides the value. The method is overloaded and accepts different data types. The key array is used to access values in nested elements. |\r\n|||\r\n\r\n### Duplicate keys\r\n\r\nThe JSON Format allows a user to have duplicate keys in his json document, e.g.\r\n\r\n```JSON\r\n{\r\n\"key\" : \"my value\",\r\n\"key\" : 1234 \r\n}\r\n```\r\n\r\nHowever, the norm does not define, how duplicate keys should be processed. In case of a duplicate key, this library will alwys try to parse the first key and ignore the second one.\r\n\r\n## Serializing\r\n\r\n## [JsonDocument](docs/JsonDocument.md)\r\n\r\n## [JsonObject](docs/JsonObject.md)\r\n\r\n## Examples\r\n\r\n### Example how to use the JSON library\r\n\r\nThis example shows in how to create, serialize, parse and reset a JSON document.\r\n\r\n```iec-st\r\nUSING Simatic.Ax.Conversion;\r\nUSING Simatic.Ax.Json;\r\n\r\nCONFIGURATION MyConfiguration\r\n    TASK Main (INTERVAL := T#100ms, PRIORITY := 1);\r\n    PROGRAM P1 WITH Main: MyProgram;\r\n    VAR_GLOBAL\r\n        SerializedDocument : STRING;\r\n        ParsedValue : DINT;\r\n    END_VAR\r\nEND_CONFIGURATION\r\n\r\nPROGRAM MyProgram\r\n    VAR_EXTERNAL\r\n        SerializedDocument : STRING;\r\n        ParsedValue : DINT;\r\n    END_VAR\r\n    VAR\r\n        doc : JsonDocument;\r\n        docBuffer : ARRAY[0..200] OF CHAR;\r\n        myBoolean : JsonBoolean := (Value := TRUE, Key := 'myBoolean');\r\n        myInt : JsonInt := (Value := 1234, Key := 'myInt');\r\n        myDint : JsonDInt := (Value := DINT#12345678, Key := 'myDint');\r\n        myObject : JsonObject := (Key := 'myObject');\r\n        deserializer : Deserializer;\r\n        keyFound : BOOL;\r\n        dintValue : DINT;\r\n        keyArray : ARRAY[0..1] OF STRING := ['myObject', 'myDint'];\r\n        step : Steps;\r\n    END_VAR\r\n    VAR_TEMP\r\n    END_VAR\r\n    CASE step OF\r\n        Steps#CreateDocument2:\r\n            // Create nested JSON document which looks like:\r\n            // {\"myBoolean\": true, \"myObject\": {\"myInt\": 1234, \"myDint\": 12345678}}\r\n            myObject.AddElement(myInt);\r\n            myObject.AddElement(myDint);\r\n            doc.AddElement(myBoolean);\r\n            doc.AddElement(myObject);\r\n            step := Steps#SerializeDocument2;\r\n        Steps#SerializeDocument2:\r\n            // Serialize the document {\"myBoolean\": true, \"myObject\": {\"myInt\": 1234, \"myDint\": 12345678}}\r\n            doc.buffer := REF(docBuffer);\r\n            doc.Serialize(doc.buffer);\r\n            SerializedDocument := Arrays.ToString(arr := doc.buffer);\r\n            step := Steps#ParseDocument2;\r\n            ;\r\n        Steps#ParseDocument2:\r\n            // Parse Document for the value of the nested key `myObject.myDint` and expect `12345678`\r\n            // Get Values from a nested element\r\n            deserializer.SetBuffer(REF(doc.buffer));\r\n            keyFound := deserializer.TryParse(keyArray, dintValue);\r\n            ParsedValue := dintValue;\r\n            step := Steps#ResetJSonDocument2;\r\n            ;\r\n        Steps#ResetJSonDocument2:\r\n            // ResetJSonDocument 2nd configuration\r\n            doc.Reset();\r\n            step := Steps#CreateDocument2;\r\n            ;\r\n    END_CASE;\r\nEND_PROGRAM\r\n\r\nTYPE\r\n    Steps : (CreateDocument2, SerializeDocument2, ParseDocument2, ResetJSonDocument2) := CreateDocument2;\r\nEND_TYPE\r\n```\r\n\r\n### Application Example\r\n\r\nA complete application example, you can find here:\r\n\r\n[JSON Application Example](https://github.com/simatic-ax/ae-json-library)\r\n\r\n## Contribution\r\n\r\nThanks for your interest in contributing. Anybody is free to report bugs, unclear documentation, and other problems regarding this repository in the Issues section or, even better, is free to propose any changes to this repository using Merge Requests.\r\n\r\n### Markdownlint-cli\r\n\r\nThis workspace will be checked by the [markdownlint-cli](https://github.com/igorshubovych/markdownlint-cli) (there is also documented ho to install the tool) tool in the CI workflow automatically.  \r\nTo avoid, that the CI workflow fails because of the markdown linter, you can check all markdown files locally by running the markdownlint with:\r\n\r\n```sh\r\nmarkdownlint **/*.md --fix\r\n```\r\n\r\n## License and Legal information\r\n\r\nPlease read the [Legal information](LICENSE.md)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimatic-ax%2Fjson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimatic-ax%2Fjson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimatic-ax%2Fjson/lists"}