{"id":18445616,"url":"https://github.com/fbarresi/twincat.jsonextension","last_synced_at":"2025-04-08T00:31:38.223Z","repository":{"id":44617753,"uuid":"196068008","full_name":"fbarresi/TwinCAT.JsonExtension","owner":"fbarresi","description":"TwinCAT variables to and from json ","archived":false,"fork":false,"pushed_at":"2024-02-04T14:10:56.000Z","size":117,"stargazers_count":50,"open_issues_count":1,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-23T03:06:40.688Z","etag":null,"topics":["beckhoff","json","twincat","twincat-ads"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fbarresi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"fbarresi"}},"created_at":"2019-07-09T19:09:33.000Z","updated_at":"2024-12-05T03:42:00.000Z","dependencies_parsed_at":"2023-01-29T20:46:17.939Z","dependency_job_id":"53e69b3c-e84d-4e96-b48e-42221a65c81a","html_url":"https://github.com/fbarresi/TwinCAT.JsonExtension","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbarresi%2FTwinCAT.JsonExtension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbarresi%2FTwinCAT.JsonExtension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbarresi%2FTwinCAT.JsonExtension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fbarresi%2FTwinCAT.JsonExtension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fbarresi","download_url":"https://codeload.github.com/fbarresi/TwinCAT.JsonExtension/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247755338,"owners_count":20990616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["beckhoff","json","twincat","twincat-ads"],"created_at":"2024-11-06T07:06:35.177Z","updated_at":"2025-04-08T00:31:37.914Z","avatar_url":"https://github.com/fbarresi.png","language":"C#","funding_links":["https://github.com/sponsors/fbarresi"],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"right\" height=\"120\" src=\"https://raw.githubusercontent.com/fbarresi/TwinCAT.JsonExtension/master/doc/images/logo.jpg\"\u003e\n\n# TwinCAT.JsonExtension\nTwinCAT variables to and from json \n\n[![Build status](https://ci.appveyor.com/api/projects/status/4ggo35buwmno05u2/branch/master?svg=true)](https://ci.appveyor.com/project/fbarresi/twincat-jsonextension/branch/master)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/6286aa6bb6f2402fa4f7553d749a5a8a)](https://www.codacy.com/manual/fbarresi/TwinCAT.JsonExtension?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=fbarresi/TwinCAT.JsonExtension\u0026amp;utm_campaign=Badge_Grade)\n[![codecov](https://codecov.io/gh/fbarresi/TwinCAT.JsonExtension/branch/master/graph/badge.svg)](https://codecov.io/gh/fbarresi/TwinCAT.JsonExtension)\n![Licence](https://img.shields.io/github/license/fbarresi/twincat.jsonextension.svg)\n[![Nuget Version](https://img.shields.io/nuget/v/TwinCAT.JsonExtension.svg)](https://www.nuget.org/packages/TwinCAT.JsonExtension/)\n\nBring the power of Json.Net to TwinCAT\n\nTranform DUTs decorated with the _custom_ **Json-Attribute** like this:\n\n```reStructuredText\nTYPE JsonDUT :\nSTRUCT\n\t{attribute 'json' := 'message'}\n\tsMessage : STRING := 'test';\n\tiResponse : INT;\n\t{attribute 'json' := 'status'}\n\tsStatus : STRING := 'success';\n\t{attribute 'json' := 'numbers'}\n\tdaNumbers : ARRAY[1..3] OF DINT := [1,2,3];\nEND_STRUCT\nEND_TYPE\n```\n\ninto this (and back) **recursively** and absolutely **type-independent**:\n\n```javascript\n{\n  \"message\": \"test\",\n  \"status\" : \"success\",\n  \"numbers\" : [1,2,3]\n}\n```\n\nonly calling this two extension methods on your connected `AdsClient`:\n```csharp\nvar json = await client.ReadJson(\"GVL.JsonDutVariable\")\n```\n\n```csharp\nawait client.WriteJson(\"GVL.JsonDutVariable\", json);\n```\n\n### Options\n#### Progress indication\nFor lengthy operations, a progress indiciator can be used to give some feedback about the current progress. By passing a `Progress\u003cint\u003e` object as parameter to `ReadJson` or `WriteJson` it is possible to count the total number of primitive types (INT, DINT, REAL, ...) that were read or written to the PLC, respectively.\n\n```csharp\nint objects = 0;\nvar progress = new Progress\u003cint\u003e();\nprogress.ProgressChanged += (sender, args) =\u003e { objects++; Console.CursorLeft = 0; Console.Write(objects); };\n\nConsole.WriteLine(\"Primitives read from PLC\");\nawait client.ReadJson(\"GVL.JsonDutVariable\", progress: progress);\n\nConsole.WriteLine(\"\\nPrimitives written to  PLC\");\nawait client.WriteJson(\"GVL.JsonDutVariable\", json, progress: progress);\n```\n\n#### Enumeration stringify\nValues of enumerations are by default started as integer values. However, sometimes it is beneficial to store said values as strings. This can be achieved by the `stringify` parameter.\n\n```csharp\nawait client.ReadJson(\"GVL.JsonDutVariable\", force: true, stringifyEnums: true);\n```\n\n\n#### Read/Write without json attribute\nThe attributes mentioned above are optional when using this library. The following example achieves a similar result. The only difference\nis the instance names in the generated json file.\n\n```reStructuredText\nTYPE JsonDUT :\nSTRUCT\n\tsMessage : STRING := 'test';\n\tiResponse : INT;\n\tsStatus : STRING := 'success';\n\tdaNumbers : ARRAY[1..3] OF DINT := [1,2,3];\nEND_STRUCT\nEND_TYPE\n```\nyields\n\n```javascript\n{\n  \"sMessage\": \"test\",\n  \"iResponse\" : 0,\n  \"sStatus\": \"success\",\n  \"daNumbers\" : [1,2,3]\n}\n```\n\nby calling the ReadJsonAsync method on your connected `AdsClient`\n```csharp\nvar json = await client.ReadJson(\"GVL.JsonDutVariable\", force: true);\n```\n\nHave fun using this simple package and don't forget to **star this project**!\n\n## Referenced projects\n\nWould you like to see the power of **TwinCAT.JsonExtension** in action?\n\nThen checkout [BeckhoffHttpClient](https://github.com/fbarresi/BeckhoffHttpClient), an _unofficial_ TwinCAT function for HTTP requests\n\nor\n\n[TwincatAdsTool](https://github.com/fbarresi/TwincatAdsTool) your swiss knife for twincat development.\n\n## Credits\n\nSpecial thanks to [JetBrains](https://www.jetbrains.com/?from=TwinCAT.JsonExtension) for supporting this open source project.\n\n\u003ca href=\"https://www.jetbrains.com/?from=TwinCAT.JsonExtension\"\u003e\u003cimg height=\"200\" src=\"https://www.jetbrains.com/company/brand/img/jetbrains_logo.png\"\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbarresi%2Ftwincat.jsonextension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffbarresi%2Ftwincat.jsonextension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffbarresi%2Ftwincat.jsonextension/lists"}