{"id":20915784,"url":"https://github.com/brainelectronics/simplejson","last_synced_at":"2026-04-12T19:49:27.589Z","repository":{"id":69601918,"uuid":"265295540","full_name":"brainelectronics/simpleJson","owner":"brainelectronics","description":"JSON encoder made by linked lists","archived":false,"fork":false,"pushed_at":"2020-05-31T15:13:47.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T16:24:35.320Z","etag":null,"topics":["c","debugging-tool","json","json-encoder","json-parser","json-schema","linked-list","simple"],"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/brainelectronics.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-19T16:04:57.000Z","updated_at":"2020-05-31T15:13:50.000Z","dependencies_parsed_at":"2023-05-31T12:15:42.268Z","dependency_job_id":null,"html_url":"https://github.com/brainelectronics/simpleJson","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/brainelectronics%2FsimpleJson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2FsimpleJson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2FsimpleJson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brainelectronics%2FsimpleJson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brainelectronics","download_url":"https://codeload.github.com/brainelectronics/simpleJson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243307490,"owners_count":20270264,"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":["c","debugging-tool","json","json-encoder","json-parser","json-schema","linked-list","simple"],"created_at":"2024-11-18T16:18:21.181Z","updated_at":"2025-12-24T19:04:30.052Z","avatar_url":"https://github.com/brainelectronics.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Linked list based JSON encoder\n\nThis is a very simple JSON encoder written in C.\n\nThe code itself is not very complex and theirby easy to understand. It has been intentionally kept simple with a very open MIT license, see the [LICENSE.md](LICENSE.md), so that it can be taken apart and reused in other applications.\n\n## Common API\n### List operations\n\nCheck whether the linked list contains elements\n```C\nbool isEmpty(struct Node** head_ref);\n```\n\nGet length of linked list. Nested lists are counted as +1\n```C\nint getLength(struct Node** head_ref);\n```\n\n### Print functions\n\nPrint content of a Node.\n```C\nvoid printNodeContent(struct Node* pNode, bool pretty = false, int indentationNumber = 0);\n```\n\nPrint complete linked list in JSON format. Use the `pretty` parameter to print the JSON in styled format (indentations).\n```C\nvoid printJson(struct Node** head_ref, bool pretty = false, int indentationNumber = 1);\nvoid printJsonChildContent(struct Node* pNode, bool pretty = false, int indentationNumber = 1);\n```\n\n### Search functions\n\nSearch for an element in the linked list/JSON by key (number) or keyStr (name of element).\n```C\nstruct Node* searchForKey(struct Node** head_ref, int key = 0, bool deepSearch=true);\nstruct Node* searchForKeyString(struct Node** head_ref, const char* keyStr=\"\", bool deepSearch=true);\nstruct Node* searchForNode(struct Node** head_ref, int key = 0, const char* keyStr=\"\", bool deepSearch=true);\n```\n\n### Add elements\n\nThe maximum number of characters for the key is limited to 50. This can be changed in the [jsonHelper.h](src/jsonHelper.h) file.\n\nIn case a element of this name already exists, the value will be overwritten. Thereby it is always safe to call add\u003cSomething\u003eNode in case you are not sure whether this key already exists. If it does not yet exist, it will be created of course.\n\n#### General\n\nAs only a void pointer is stored in the Node, a seperate element of the Node struct is set according to the type which is stored.\n\nAll elements like numbers, floats, strings, arrays or nested Nodes are represented by a data type, which is defined in the `dataType` enum.\n\nThe functions are just wrappers around the `addGeneralNode` function.\n\n```C\nstruct Node* createGeneralNode(const char* keyStr, void* pVal, dataType type);\nvoid addGeneralNode(struct Node** head_ref, const char* keyStr, void* pVal, dataType type);\n```\n\n#### Integers\n\n```C\nvoid addU8IntegerNode(struct Node** head_ref, const char* keyStr, void* pVal);\nvoid addS8IntegerNode(struct Node** head_ref, const char* keyStr, void* pVal);\nvoid addU16IntegerNode(struct Node** head_ref, const char* keyStr, void* pVal);\nvoid addS16IntegerNode(struct Node** head_ref, const char* keyStr, void* pVal);\nvoid addU32IntegerNode(struct Node** head_ref, const char* keyStr, void* pVal);\nvoid addS32IntegerNode(struct Node** head_ref, const char* keyStr, void* pVal);\nvoid addIntegerNode(struct Node** head_ref, const char* keyStr, void* pVal);\n```\n\nExample:\n```C\nstruct Node* head = getNode();\n\n// add an unsigned int (0...65536) Node to the linked list\nuint16_t abcU16 = 32800;\naddU16IntegerNode(\u0026head, \"someKeyForThisUInt16\", \u0026abcU16);\n\n// print the JSON with pretty indentation\nprintJson(\u0026head, true);\n```\n\n```JSON\n{\n  \"someKeyForThisUInt16\": 32800,\n}\n```\n\n#### Floats\n```C\nvoid addFloatNode(struct Node** head_ref, const char* keyStr, void* pVal);\n```\n\nExample:\n```C\nstruct Node* head = getNode();\n\n// add a float Node to the linked list\nfloat abcF = 1.23456890;\naddFloatNode(\u0026head, \"floatNode\", \u0026abcF);\n\n// floats will be printed with a precision of 5 decimals\n// print the JSON with pretty indentation\nprintJson(\u0026head, true);\n```\n\n```JSON\n{\n  \"floatNode\": 1.23456,\n}\n```\n\n#### Strings\n```C\nvoid addStringNode(struct Node** head_ref, const char* keyStr, void* pVal);\n```\n\nExample:\n```C\nstruct Node* head = getNode();\n\n// add a string Node to the linked list\nchar* pSomeString = (char *) calloc(255, sizeof(char));\nsprintf(pSomeString, \"asdf bla bla %d\", 1234);\naddStringNode(\u0026head, \"keyOfThisNode\", pSomeString);\n\n// print the JSON with pretty indentation\nprintJson(\u0026head, true);\n```\n\n```JSON\n{\n  \"keyOfThisNode\": \"asdf bla bla 1234\",\n}\n```\n\n#### Bools\n```C\nvoid addBoolNode(struct Node** head_ref, const char* keyStr, void* pVal);\n```\n\nExample:\n```C\nstruct Node* head = getNode();\n\n// add a boolean Node to the linked list\nbool abcB = false;\naddBoolNode(\u0026head, \"exampleOfBool\", \u0026abcB);\n\n// print the JSON with pretty indentation\nprintJson(\u0026head, true);\n```\n\n```JSON\n{\n  \"exampleOfBool\": false,\n}\n```\n\n#### Array of integers\n```C\nstruct Node* createArrayNode(const char* keyStr, int* pVal, int numberOfElements);\nvoid addArrayNode(struct Node** head_ref, const char* keyStr, void* pVal, int numberOfElements);\n```\n\nExample:\n```C\nstruct Node* head = getNode();\n\n// add array Node to the linked list\nint arr2[] = { 11, 22, 33, 44, 55, 66, 77 };\nint numOfElements = sizeof(arr2) / sizeof(arr2[0]);\naddArrayNode(\u0026head, \"arrayNode\", arr2, numOfElements);\n\n// print the JSON with pretty indentation\nprintJson(\u0026head, true);\n```\n\n```JSON\n{\n  \"arrayNode\": [11, 22, 33, 44, 55, 66, 77],\n}\n```\n\n#### Nested elements\n```C\nstruct Node* createNestedNode(const char* keyStr);\nstruct Node* addNestedNode(struct Node** head_ref, const char* keyStr);\n\nstruct Node* getNestedNodeHead(struct Node** head_ref, const char* keyStr, bool createOnError = false);\nstruct Node* clearNestedNodeContent(struct Node** head_ref, const char* keyStr);\n```\n\nExample:\n```C\nstruct Node* head = getNode();\n\n// add a nested Node list to the linked list\nstruct Node* nestedHead = addNestedNode(\u0026head, \"nodeNode\");\n\n// append a nested integer Node to the first sub Node (optional)\nint bcd = 234;\naddIntegerNode(\u0026nestedHead, \"intNestedNode\", \u0026bcd);\n\n// append a nested string Node to the first sub Node (optional)\nchar* pNestedString = (char *) calloc(255, sizeof(char));\nsprintf(pNestedString, \"Hello World! @ %d\", 9876);\naddStringNode(\u0026nestedHead, \"strNestedNode\", pNestedString);\n\n// append a nested nested Node to the first sub Node (optional)\nstruct Node* nestedNestedHead = addNestedNode(\u0026nestedHead, \"nodeNestedNode\");\n// append a nested integer Node to the first sub Node (optional)\nfloat cde = 3.141592;\naddFloatNode(\u0026nestedNestedHead, \"floatNestedNestedNode\", \u0026cde);\n\n// print the JSON with pretty indentation\nprintJson(\u0026head, true);\n```\n\n```JSON\n{\n  \"nodeNode\": {\n    \"intNestedNode\": 234,\n    \"strNestedNode\": \"Hello World! @ 9876\",\n    \"nodeNestedNode\": {\n      \"floatNestedNestedNode\": 3.15159\n    }\n  }\n}\n```\n\n## Usecase\n\nUse this library together with the [SerialDebugMonitor](https://github.com/brainelectronics/SerialDebugMonitor) and a microcontroller, to view the data in an easy and human readable way.\n\n## Authors\n\n* **brainelectronics** - *Initial Work* - [brainelectronics](https://github.com/brainelectronics/simpleJson)\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainelectronics%2Fsimplejson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainelectronics%2Fsimplejson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainelectronics%2Fsimplejson/lists"}