diff --git a/images/arrow-down.png b/images/arrow-down.png new file mode 100644 index 0000000..5c55c6a Binary files /dev/null and b/images/arrow-down.png differ diff --git a/images/octocat-small.png b/images/octocat-small.png new file mode 100644 index 0000000..57c1e44 Binary files /dev/null and b/images/octocat-small.png differ diff --git a/index.html b/index.html index 4af270e..9ecb32e 100644 --- a/index.html +++ b/index.html @@ -1,51 +1,54 @@ - + - + - - - - + parson by kgabis + + + + + - parson by kgabis - -
-
+
+
+

parson

+

Lightweight json library written in C.

-
-

parson

-

Lightweight json parser and reader written in C.

-
+ -
- Download .zip - Download .tar.gz - View on GitHub -
+

This project is maintained by kgabis

-
-
-

About

+
+
+

+About

-

Parson is a lighweight json parser and reader written in C.

+

Parson is a lighweight json library written in C.

-

Features

+

+Features

    +
  • Full JSON support
  • Lightweight (only 2 files)
  • Simple API
  • Addressing json values with dot notation (similiar to C structs or objects in most OO languages, e.g. "objectA.objectB.value")
  • C89 compatible
  • Test suites
  • -

Installation

+

+Installation

-

Run the following code:

+

Run:

git clone https://github.com/kgabis/parson.git
 
@@ -54,11 +57,15 @@

Run make test to compile and run tests.

-

Example

+

+Examples

+ +

+Parsing JSON

-

Here is a function, which prints basic commit info (date, sha and author) from a github repository. It's also included in tests.c file, you can just uncomment and run it.

+

Here is a function, which prints basic commit info (date, sha and author) from a github repository.

-
void print_commits_info(const char *username, const char *repo) {
+
void print_commits_info(const char *username, const char *repo) {
     JSON_Value *root_value;
     JSON_Array *commits;
     JSON_Object *commit;
@@ -112,17 +119,88 @@
 ...
 
-

License

+

+Persistence

+ +

In this example I'm using parson to save user information to a file and then load it and validate later.

+ +
void persistence_example(void) {
+    JSON_Value *schema = json_parse_string("{\"name\":\"\"}");
+    JSON_Value *user_data = json_parse_file("user_data.json");
+    char buf[256];
+    const char *name = NULL;
+    if (!user_data || !json_validate(schema, user_data) == JSONSuccess) {
+        puts("Enter your name:");
+        scanf("%s", buf);
+        user_data = json_value_init_object();
+        json_object_set_string(json_object(user_data), "name", buf);
+        json_serialize_to_file(user_data, "user_data.json");
+    }
+    name = json_object_get_string(json_object(user_data), "name");
+    printf("Hello, %s.", name);
+    json_value_free(schema);
+    json_value_free(user_data);
+    return;
+}
+
-

The MIT License (MIT)

-
+

+Serialization

+ +

Creating JSON values is very simple thanks to the dot notation. +Object hierarchy is automatically created when addressing specific fields. +In the following example I create a simple JSON value containing basic information about a person.

+ +
void serialization_example(void) {
+    JSON_Value *root_value = json_value_init_object();
+    JSON_Object *root_object = json_value_get_object(root_value);
+    char *serialized_string = NULL;
+    json_object_set_string(root_object, "name", "John Smith");
+    json_object_set_number(root_object, "age", 25);
+    json_object_dotset_string(root_object, "address.city", "Cupertino");
+    json_object_dotset_value(root_object, "contact.emails", json_parse_string("[\"email@example.com\",\"email2@example.com\"]"));
+    serialized_string = json_serialize_to_string(root_value);
+    puts(serialized_string);
+    json_free_serialized_string(serialized_string);
+}
 
-        
+
+ +

Created value (after formatting outside parson):

+ +
{  
+   "name":"John Smith",
+   "age":25,
+   "address":{  
+      "city":"Cupertino"
+   },
+   "contact":{  
+      "emails":[  
+         "email@example.com",
+         "email2@example.com"
+      ]
+   }
+}
+
+ +

+Contributing

+ +

I will always merge working bug fixes. However, if you want to add something to the API, +I won't merge it without prior discussion. +Remember to follow parson's code style and write appropriate tests.

- @@ -133,7 +211,5 @@ } catch(err) {} -
-
- \ No newline at end of file + diff --git a/javascripts/scale.fix.js b/javascripts/scale.fix.js new file mode 100644 index 0000000..08716c0 --- /dev/null +++ b/javascripts/scale.fix.js @@ -0,0 +1,20 @@ +fixScale = function(doc) { + + var addEvent = 'addEventListener', + type = 'gesturestart', + qsa = 'querySelectorAll', + scales = [1, 1], + meta = qsa in doc ? doc[qsa]('meta[name=viewport]') : []; + + function fix() { + meta.content = 'width=device-width,minimum-scale=' + scales[0] + ',maximum-scale=' + scales[1]; + doc.removeEventListener(type, fix, true); + } + + if ((meta = meta[meta.length - 1]) && addEvent in doc) { + fix(); + scales = [.25, 1.6]; + doc[addEvent](type, fix, true); + } + +}; \ No newline at end of file diff --git a/params.json b/params.json index 234dc62..d8143ba 100644 --- a/params.json +++ b/params.json @@ -1 +1 @@ -{"name":"parson","body":"##About\r\nParson is a lighweight [json](http://json.org) parser and reader written in C. \r\n\r\n##Features\r\n* Lightweight (only 2 files)\r\n* Simple API\r\n* Addressing json values with dot notation (similiar to C structs or objects in most OO languages, e.g. \"objectA.objectB.value\")\r\n* C89 compatible\r\n* Test suites\r\n\r\n##Installation\r\nRun the following code:\r\n```\r\ngit clone https://github.com/kgabis/parson.git\r\n```\r\nand copy parson.h and parson.c to you source code tree.\r\n\r\nRun ```make test``` to compile and run tests.\r\n\r\n##Example\r\nHere is a function, which prints basic commit info (date, sha and author) from a github repository. It's also included in tests.c file, you can just uncomment and run it.\r\n```c\r\nvoid print_commits_info(const char *username, const char *repo) {\r\n JSON_Value *root_value;\r\n JSON_Array *commits;\r\n JSON_Object *commit;\r\n size_t i;\r\n \r\n char curl_command[512];\r\n char cleanup_command[256];\r\n char output_filename[] = \"commits.json\";\r\n \r\n /* it ain't pretty, but it's not a libcurl tutorial */\r\n sprintf(curl_command, \r\n \"curl -s \\\"https://api.github.com/repos/%s/%s/commits\\\" > %s\",\r\n username, repo, output_filename);\r\n sprintf(cleanup_command, \"rm -f %s\", output_filename);\r\n system(curl_command);\r\n \r\n /* parsing json and validating output */\r\n root_value = json_parse_file(output_filename);\r\n if (json_value_get_type(root_value) != JSONArray) {\r\n system(cleanup_command);\r\n return;\r\n }\r\n \r\n /* getting array from root value and printing commit info */\r\n commits = json_value_get_array(root_value);\r\n printf(\"%-10.10s %-10.10s %s\\n\", \"Date\", \"SHA\", \"Author\");\r\n for (i = 0; i < json_array_get_count(commits); i++) {\r\n commit = json_array_get_object(commits, i);\r\n printf(\"%.10s %.10s %s\\n\",\r\n json_object_dotget_string(commit, \"commit.author.date\"),\r\n json_object_get_string(commit, \"sha\"),\r\n json_object_dotget_string(commit, \"commit.author.name\"));\r\n }\r\n \r\n /* cleanup code */\r\n json_value_free(root_value);\r\n system(cleanup_command);\r\n}\r\n\r\n```\r\nCalling ```print_commits_info(\"torvalds\", \"linux\");``` prints: \r\n```\r\nDate SHA Author\r\n2012-10-15 dd8e8c4a2c David Rientjes\r\n2012-10-15 3ce9e53e78 Michal Marek\r\n2012-10-14 29bb4cc5e0 Randy Dunlap\r\n2012-10-15 325adeb55e Ralf Baechle\r\n2012-10-14 68687c842c Russell King\r\n2012-10-14 ddffeb8c4d Linus Torvalds\r\n...\r\n```\r\n\r\n##License\r\n[The MIT License (MIT)](http://opensource.org/licenses/mit-license.php)","note":"Don't delete this file! It's used internally to help with page regeneration.","tagline":"Lightweight json parser and reader written in C.","google":"UA-35563760-2"} \ No newline at end of file +{"name":"parson","tagline":"Lightweight json library written in C.","body":"##About\r\nParson is a lighweight [json](http://json.org) library written in C.\r\n\r\n##Features\r\n* Full JSON support\r\n* Lightweight (only 2 files)\r\n* Simple API\r\n* Addressing json values with dot notation (similiar to C structs or objects in most OO languages, e.g. \"objectA.objectB.value\")\r\n* C89 compatible\r\n* Test suites\r\n\r\n##Installation\r\nRun:\r\n```\r\ngit clone https://github.com/kgabis/parson.git\r\n```\r\nand copy parson.h and parson.c to you source code tree.\r\n\r\nRun ```make test``` to compile and run tests.\r\n\r\n##Examples\r\n###Parsing JSON\r\nHere is a function, which prints basic commit info (date, sha and author) from a github repository. \r\n```c\r\nvoid print_commits_info(const char *username, const char *repo) {\r\n JSON_Value *root_value;\r\n JSON_Array *commits;\r\n JSON_Object *commit;\r\n size_t i;\r\n \r\n char curl_command[512];\r\n char cleanup_command[256];\r\n char output_filename[] = \"commits.json\";\r\n \r\n /* it ain't pretty, but it's not a libcurl tutorial */\r\n sprintf(curl_command, \r\n \"curl -s \\\"https://api.github.com/repos/%s/%s/commits\\\" > %s\",\r\n username, repo, output_filename);\r\n sprintf(cleanup_command, \"rm -f %s\", output_filename);\r\n system(curl_command);\r\n \r\n /* parsing json and validating output */\r\n root_value = json_parse_file(output_filename);\r\n if (json_value_get_type(root_value) != JSONArray) {\r\n system(cleanup_command);\r\n return;\r\n }\r\n \r\n /* getting array from root value and printing commit info */\r\n commits = json_value_get_array(root_value);\r\n printf(\"%-10.10s %-10.10s %s\\n\", \"Date\", \"SHA\", \"Author\");\r\n for (i = 0; i < json_array_get_count(commits); i++) {\r\n commit = json_array_get_object(commits, i);\r\n printf(\"%.10s %.10s %s\\n\",\r\n json_object_dotget_string(commit, \"commit.author.date\"),\r\n json_object_get_string(commit, \"sha\"),\r\n json_object_dotget_string(commit, \"commit.author.name\"));\r\n }\r\n \r\n /* cleanup code */\r\n json_value_free(root_value);\r\n system(cleanup_command);\r\n}\r\n\r\n```\r\nCalling ```print_commits_info(\"torvalds\", \"linux\");``` prints: \r\n```\r\nDate SHA Author\r\n2012-10-15 dd8e8c4a2c David Rientjes\r\n2012-10-15 3ce9e53e78 Michal Marek\r\n2012-10-14 29bb4cc5e0 Randy Dunlap\r\n2012-10-15 325adeb55e Ralf Baechle\r\n2012-10-14 68687c842c Russell King\r\n2012-10-14 ddffeb8c4d Linus Torvalds\r\n...\r\n```\r\n\r\n###Persistence\r\nIn this example I'm using parson to save user information to a file and then load it and validate later.\r\n```c\r\nvoid persistence_example(void) {\r\n JSON_Value *schema = json_parse_string(\"{\\\"name\\\":\\\"\\\"}\");\r\n JSON_Value *user_data = json_parse_file(\"user_data.json\");\r\n char buf[256];\r\n const char *name = NULL;\r\n if (!user_data || !json_validate(schema, user_data) == JSONSuccess) {\r\n puts(\"Enter your name:\");\r\n scanf(\"%s\", buf);\r\n user_data = json_value_init_object();\r\n json_object_set_string(json_object(user_data), \"name\", buf);\r\n json_serialize_to_file(user_data, \"user_data.json\");\r\n }\r\n name = json_object_get_string(json_object(user_data), \"name\");\r\n printf(\"Hello, %s.\", name);\r\n json_value_free(schema);\r\n json_value_free(user_data);\r\n return;\r\n}\r\n```\r\n\r\n###Serialization\r\nCreating JSON values is very simple thanks to the dot notation. \r\nObject hierarchy is automatically created when addressing specific fields. \r\nIn the following example I create a simple JSON value containing basic information about a person.\r\n```c\r\nvoid serialization_example(void) {\r\n JSON_Value *root_value = json_value_init_object();\r\n JSON_Object *root_object = json_value_get_object(root_value);\r\n char *serialized_string = NULL;\r\n json_object_set_string(root_object, \"name\", \"John Smith\");\r\n json_object_set_number(root_object, \"age\", 25);\r\n json_object_dotset_string(root_object, \"address.city\", \"Cupertino\");\r\n json_object_dotset_value(root_object, \"contact.emails\", json_parse_string(\"[\\\"email@example.com\\\",\\\"email2@example.com\\\"]\"));\r\n serialized_string = json_serialize_to_string(root_value);\r\n puts(serialized_string);\r\n json_free_serialized_string(serialized_string);\r\n}\r\n\r\n```\r\n\r\nCreated value (after formatting outside parson):\r\n```\r\n{ \r\n \"name\":\"John Smith\",\r\n \"age\":25,\r\n \"address\":{ \r\n \"city\":\"Cupertino\"\r\n },\r\n \"contact\":{ \r\n \"emails\":[ \r\n \"email@example.com\",\r\n \"email2@example.com\"\r\n ]\r\n }\r\n}\r\n```\r\n\r\n##Contributing\r\n\r\nI will always merge *working* bug fixes. However, if you want to add something to the API, \r\nI *won't* merge it without prior discussion.\r\nRemember to follow parson's code style and write appropriate tests.\r\n\r\n##License\r\n[The MIT License (MIT)](http://opensource.org/licenses/mit-license.php)","google":"UA-35563760-2","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file diff --git a/stylesheets/styles.css b/stylesheets/styles.css new file mode 100644 index 0000000..c2c94b4 --- /dev/null +++ b/stylesheets/styles.css @@ -0,0 +1,421 @@ +@import url(https://fonts.googleapis.com/css?family=Arvo:400,700,400italic); + +/* MeyerWeb Reset */ + +html, body, div, span, applet, object, iframe, +h1, h2, h3, h4, h5, h6, p, blockquote, pre, +a, abbr, acronym, address, big, cite, code, +del, dfn, em, img, ins, kbd, q, s, samp, +small, strike, strong, sub, sup, tt, var, +b, u, i, center, +dl, dt, dd, ol, ul, li, +fieldset, form, label, legend, +table, caption, tbody, tfoot, thead, tr, th, td, +article, aside, canvas, details, embed, +figure, figcaption, footer, header, hgroup, +menu, nav, output, ruby, section, summary, +time, mark, audio, video { + margin: 0; + padding: 0; + border: 0; + font: inherit; + vertical-align: baseline; +} + + +/* Base text styles */ + +body { + padding:10px 50px 0 0; + font-family:"Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 14px; + color: #232323; + background-color: #FBFAF7; + margin: 0; + line-height: 1.8em; + -webkit-font-smoothing: antialiased; + +} + +h1, h2, h3, h4, h5, h6 { + color:#232323; + margin:36px 0 10px; +} + +p, ul, ol, table, dl { + margin:0 0 22px; +} + +h1, h2, h3 { + font-family: Arvo, Monaco, serif; + line-height:1.3; + font-weight: normal; +} + +h1,h2, h3 { + display: block; + border-bottom: 1px solid #ccc; + padding-bottom: 5px; +} + +h1 { + font-size: 30px; +} + +h2 { + font-size: 24px; +} + +h3 { + font-size: 18px; +} + +h4, h5, h6 { + font-family: Arvo, Monaco, serif; + font-weight: 700; +} + +a { + color:#C30000; + font-weight:200; + text-decoration:none; +} + +a:hover { + text-decoration: underline; +} + +a small { + font-size: 12px; +} + +em { + font-style: italic; +} + +strong { + font-weight:700; +} + +ul { + list-style: inside; + padding-left: 25px; +} + +ol { + list-style: decimal inside; + padding-left: 20px; +} + +blockquote { + margin: 0; + padding: 0 0 0 20px; + font-style: italic; +} + +dl, dt, dd, dl p { + font-color: #444; +} + +dl dt { + font-weight: bold; +} + +dl dd { + padding-left: 20px; + font-style: italic; +} + +dl p { + padding-left: 20px; + font-style: italic; +} + +hr { + border:0; + background:#ccc; + height:1px; + margin:0 0 24px; +} + +/* Images */ + +img { + position: relative; + margin: 0 auto; + max-width: 650px; + padding: 5px; + margin: 10px 0 32px 0; + border: 1px solid #ccc; +} + +p img { + display: inline; + margin: 0; + padding: 0; + vertical-align: middle; + text-align: center; + border: none; +} + +/* Code blocks */ + +code, pre { + font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace; + color:#000; + font-size:14px; +} + +pre { + padding: 4px 12px; + background: #FDFEFB; + border-radius:4px; + border:1px solid #D7D8C8; + overflow: auto; + overflow-y: hidden; + margin-bottom: 32px; +} + + +/* Tables */ + +table { + width:100%; +} + +table { + border: 1px solid #ccc; + margin-bottom: 32px; + text-align: left; + } + +th { + font-family: 'Arvo', Helvetica, Arial, sans-serif; + font-size: 18px; + font-weight: normal; + padding: 10px; + background: #232323; + color: #FDFEFB; + } + +td { + padding: 10px; + background: #ccc; + } + + +/* Wrapper */ +.wrapper { + width:960px; +} + + +/* Header */ + +header { + background-color: #171717; + color: #FDFDFB; + width:170px; + float:left; + position:fixed; + border: 1px solid #000; + -webkit-border-top-right-radius: 4px; + -webkit-border-bottom-right-radius: 4px; + -moz-border-radius-topright: 4px; + -moz-border-radius-bottomright: 4px; + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + padding: 34px 25px 22px 50px; + margin: 30px 25px 0 0; + -webkit-font-smoothing: antialiased; +} + +p.header { + font-size: 16px; +} + +h1.header { + font-family: Arvo, sans-serif; + font-size: 30px; + font-weight: 300; + line-height: 1.3em; + border-bottom: none; + margin-top: 0; +} + + +h1.header, a.header, a.name, header a{ + color: #fff; +} + +a.header { + text-decoration: underline; +} + +a.name { + white-space: nowrap; +} + +header ul { + list-style:none; + padding:0; +} + +header li { + list-style-type: none; + width:132px; + height:15px; + margin-bottom: 12px; + line-height: 1em; + padding: 6px 6px 6px 7px; + + background: #AF0011; + background: -moz-linear-gradient(top, #AF0011 0%, #820011 100%); + background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd)); + background: -webkit-linear-gradient(top, #AF0011 0%,#820011 100%); + background: -o-linear-gradient(top, #AF0011 0%,#820011 100%); + background: -ms-linear-gradient(top, #AF0011 0%,#820011 100%); + background: linear-gradient(top, #AF0011 0%,#820011 100%); + + border-radius:4px; + border:1px solid #0D0D0D; + + -webkit-box-shadow: inset 0px 1px 1px 0 rgba(233,2,38, 1); + box-shadow: inset 0px 1px 1px 0 rgba(233,2,38, 1); + +} + +header li:hover { + background: #C3001D; + background: -moz-linear-gradient(top, #C3001D 0%, #950119 100%); + background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f8f8f8), color-stop(100%,#dddddd)); + background: -webkit-linear-gradient(top, #C3001D 0%,#950119 100%); + background: -o-linear-gradient(top, #C3001D 0%,#950119 100%); + background: -ms-linear-gradient(top, #C3001D 0%,#950119 100%); + background: linear-gradient(top, #C3001D 0%,#950119 100%); +} + +a.buttons { + -webkit-font-smoothing: antialiased; + background: url(../images/arrow-down.png) no-repeat; + font-weight: normal; + text-shadow: rgba(0, 0, 0, 0.4) 0 -1px 0; + padding: 2px 2px 2px 22px; + height: 30px; +} + +a.github { + background: url(../images/octocat-small.png) no-repeat 1px; +} + +a.buttons:hover { + color: #fff; + text-decoration: none; +} + + +/* Section - for main page content */ + +section { + width:650px; + float:right; + padding-bottom:50px; +} + + +/* Footer */ + +footer { + width:170px; + float:left; + position:fixed; + bottom:10px; + padding-left: 50px; +} + +@media print, screen and (max-width: 960px) { + + div.wrapper { + width:auto; + margin:0; + } + + header, section, footer { + float:none; + position:static; + width:auto; + } + + footer { + border-top: 1px solid #ccc; + margin:0 84px 0 50px; + padding:0; + } + + header { + padding-right:320px; + } + + section { + padding:20px 84px 20px 50px; + margin:0 0 20px; + } + + header a small { + display:inline; + } + + header ul { + position:absolute; + right:130px; + top:84px; + } +} + +@media print, screen and (max-width: 720px) { + body { + word-wrap:break-word; + } + + header { + padding:10px 20px 0; + margin-right: 0; + } + + section { + padding:10px 0 10px 20px; + margin:0 0 30px; + } + + footer { + margin: 0 0 0 30px; + } + + header ul, header p.view { + position:static; + } +} + +@media print, screen and (max-width: 480px) { + + header ul li.download { + display:none; + } + + footer { + margin: 0 0 0 20px; + } + + footer a{ + display:block; + } + +} + +@media print { + body { + padding:0.4in; + font-size:12pt; + color:#444; + } +} \ No newline at end of file