{"id":13741256,"url":"https://github.com/rafagafe/tiny-json","last_synced_at":"2025-05-08T21:32:59.041Z","repository":{"id":43898855,"uuid":"70110564","full_name":"rafagafe/tiny-json","owner":"rafagafe","description":"The tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable.","archived":false,"fork":false,"pushed_at":"2024-05-10T23:28:02.000Z","size":86,"stargazers_count":348,"open_issues_count":4,"forks_count":88,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-08-04T04:07:36.585Z","etag":null,"topics":["c","embedded","json","microcontroller","parser"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":false,"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/rafagafe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"custom":["paypal.me/rafagafe"]}},"created_at":"2016-10-06T00:31:47.000Z","updated_at":"2024-07-31T07:18:05.000Z","dependencies_parsed_at":"2024-01-14T23:57:07.275Z","dependency_job_id":"4e730812-1fbb-476c-b544-13dab42ff05d","html_url":"https://github.com/rafagafe/tiny-json","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/rafagafe%2Ftiny-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafagafe%2Ftiny-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafagafe%2Ftiny-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafagafe%2Ftiny-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafagafe","download_url":"https://codeload.github.com/rafagafe/tiny-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224774712,"owners_count":17367783,"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","embedded","json","microcontroller","parser"],"created_at":"2024-08-03T04:00:57.253Z","updated_at":"2024-11-15T11:31:03.142Z","avatar_url":"https://github.com/rafagafe.png","language":"C","funding_links":["paypal.me/rafagafe"],"categories":["C Libraries"],"sub_categories":["JSON"],"readme":"# tiny-json\n\n[![Build Status](https://travis-ci.org/rafagafe/tiny-json.svg?branch=master)](https://travis-ci.org/rafagafe/tiny-json) [![GitHub contributors](https://img.shields.io/github/contributors/rafagafe/tiny-json.svg)](https://github.com/rafagafe/tiny-json/graphs/contributors)\n\ntiny-json is a versatile and easy to use json parser written in C and suitable for embedded systems. It is fast, robust and portable.\n\nIt is not only a tokenizer. You can access json data in string format or get primitive values directly as C type variables without any loss of performance.\n\nYou can access the JSON fields one on one or get their values by their names. This helps you to save a lot of source code lines and development time.\n\n* It does not use recursivity.\n* It does not use dynamic memory. The memory you use can be reserved statically.\n* There is no limit for nested levels in arrays or json objects.\n* The JSON property number limit is determined by the size of a buffer that can be statically reserved.\n\nIf you need to create JSON strings please visit: https://github.com/rafagafe/json-maker\n\n# Philosophy\n\nWhen parsing a JSON text string a tree is created by linking json_t structures. Navigating or querying this tree is very easy using the provided API.\n\nTo maintain reduced memory usage and fast processing the strings are not copied. When you request the value of a JSON element, a reference to the original JSON string is returned.\n\nTo facilitate the processing of the data the returned strings are null-terminated. This is achieved by setting the null character to JSON control characters such as commas, brackets, braces, and quotation marks.\n\n# API\nThe tiny-json API provides two types. `jsonType_t` is an enumeration for all possible JSON field types. `json_t` is a structure containing internal data which you don't need to know.\n```C\ntypedef enum {\n    JSON_OBJ, JSON_ARRAY, JSON_TEXT, JSON_BOOLEAN,\n    JSON_INTEGER, JSON_REAL, JSON_NULL\n} jsonType_t;\n```\nTo parse a JSON string use `json_create()`. We pass it an array of `json_t` for it to allocate JSON fields.\nIf the JSON string is bad formated or has more fields than the array this function returns a null pointer.\n```C\nenum { MAX_FIELDS = 4 };\njson_t pool[ MAX_FIELDS ];\n\nchar str[] = \"{ \\\"name\\\": \\\"peter\\\", \\\"age\\\": 32 }\";\t\n\njson_t const* parent = json_create( str, pool, MAX_FIELDS );\nif ( parent == NULL ) return EXIT_FAILURE;\n```\nTo get a field by its name we use `json_getProperty()`. If the field does not exist the function returns a null pointer.\nTo get the type of a field we use `json_getType()`.\n```C\njson_t const* namefield = json_getProperty( parent, \"name\" );\nif ( namefield == NULL ) return EXIT_FAILURE;\nif ( json_getType( namefield ) != JSON_TEXT ) return EXIT_FAILURE;\n```\nTo get the value of a field in string format we use `json_getValue()`. It always returns a valid null-teminated string.\n```C\nchar const* namevalue = json_getValue( namefield );\nprintf( \"%s%s%s\", \"Name: '\", namevalue, \"'.\\n\" );\n```\nFor primitive fields we can use a specific function to get the fields value directly as a C type, f.i. `json_getInteger()` or we can use `json_getValue()` to get its value in text format.\n```C\njson_t const* agefield = json_getProperty( parent, \"age\" );\nif ( agefield == NULL ) return EXIT_FAILURE;\nif ( json_getType( agefield ) != JSON_INTEGER ) return EXIT_FAILURE;\n\nint64_t agevalue = json_getInteger( agefield );\nprintf( \"%s%lld%s\", \"Age: '\", agevalue, \"'.\\n\" );\n\nchar const* agetxt = json_getValue( agefield );\nprintf( \"%s%s%s\", \"Age: '\", agetxt, \"'.\\n\" );\n```\nFor an example how to use nested JSON objects and arrays please see example-01.c.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafagafe%2Ftiny-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafagafe%2Ftiny-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafagafe%2Ftiny-json/lists"}