From 1dcb778e8cdec3999b723ce32fa7ce3a5782f89f Mon Sep 17 00:00:00 2001 From: Krzysztof Gabis Date: Mon, 24 Nov 2014 21:05:13 +0100 Subject: [PATCH] Create gh-pages branch via GitHub --- index.html | 165 ++++++++++++++++++++--------------------- params.json | 2 +- stylesheets/styles.css | 8 +- 3 files changed, 88 insertions(+), 87 deletions(-) diff --git a/index.html b/index.html index ccbcc9e..de3dccc 100644 --- a/index.html +++ b/index.html @@ -31,12 +31,12 @@

-About

+About

Parson is a lighweight json library written in C.

-Features

+Features

-Installation

+ + +

+Installation

Run:

@@ -58,53 +60,52 @@

Run make test to compile and run tests.

-Examples

+Examples

-Parsing JSON

+Parsing JSON

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) {
-    JSON_Value *root_value;
-    JSON_Array *commits;
-    JSON_Object *commit;
-    size_t i;
-
-    char curl_command[512];
-    char cleanup_command[256];
-    char output_filename[] = "commits.json";
-
-    /* it ain't pretty, but it's not a libcurl tutorial */
-    sprintf(curl_command, 
-        "curl -s \"https://api.github.com/repos/%s/%s/commits\" > %s",
-        username, repo, output_filename);
-    sprintf(cleanup_command, "rm -f %s", output_filename);
-    system(curl_command);
-
-    /* parsing json and validating output */
-    root_value = json_parse_file(output_filename);
-    if (json_value_get_type(root_value) != JSONArray) {
-        system(cleanup_command);
-        return;
-    }
-
-    /* getting array from root value and printing commit info */
-    commits = json_value_get_array(root_value);
-    printf("%-10.10s %-10.10s %s\n", "Date", "SHA", "Author");
-    for (i = 0; i < json_array_get_count(commits); i++) {
-        commit = json_array_get_object(commits, i);
-        printf("%.10s %.10s %s\n",
-               json_object_dotget_string(commit, "commit.author.date"),
-               json_object_get_string(commit, "sha"),
-               json_object_dotget_string(commit, "commit.author.name"));
-    }
-
-    /* cleanup code */
-    json_value_free(root_value);
-    system(cleanup_command);
-}
-
+
void print_commits_info(const char *username, const char *repo) {
+    JSON_Value *root_value;
+    JSON_Array *commits;
+    JSON_Object *commit;
+    size_t i;
+
+    char curl_command[512];
+    char cleanup_command[256];
+    char output_filename[] = "commits.json";
+
+    /* it ain't pretty, but it's not a libcurl tutorial */
+    sprintf(curl_command, 
+        "curl -s \"https://api.github.com/repos/%s/%s/commits\" > %s",
+        username, repo, output_filename);
+    sprintf(cleanup_command, "rm -f %s", output_filename);
+    system(curl_command);
+
+    /* parsing json and validating output */
+    root_value = json_parse_file(output_filename);
+    if (json_value_get_type(root_value) != JSONArray) {
+        system(cleanup_command);
+        return;
+    }
+
+    /* getting array from root value and printing commit info */
+    commits = json_value_get_array(root_value);
+    printf("%-10.10s %-10.10s %s\n", "Date", "SHA", "Author");
+    for (i = 0; i < json_array_get_count(commits); i++) {
+        commit = json_array_get_object(commits, i);
+        printf("%.10s %.10s %s\n",
+               json_object_dotget_string(commit, "commit.author.date"),
+               json_object_get_string(commit, "sha"),
+               json_object_dotget_string(commit, "commit.author.name"));
+    }
+
+    /* cleanup code */
+    json_value_free(root_value);
+    system(cleanup_command);
+}
 

Calling print_commits_info("torvalds", "linux"); prints:

@@ -120,51 +121,49 @@

-Persistence

+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;
-}
-
+
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 == NULL || 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;
+}

-Serialization

+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);
-    json_value_free(root_value);
-}
-
+
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);
+    json_value_free(root_value);
+}
 

Created value (after formatting outside parson):

@@ -185,14 +184,14 @@ In the following example I create a simple JSON value containing basic informati

-Contributing

+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.

-License

+License

The MIT License (MIT)

diff --git a/params.json b/params.json index 4da480e..4b8d3a3 100644 --- a/params.json +++ b/params.json @@ -1 +1 @@ -{"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 json_value_free(root_value);\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 +{"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 == NULL || 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 json_value_free(root_value);\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 index c2c94b4..647f08d 100644 --- a/stylesheets/styles.css +++ b/stylesheets/styles.css @@ -98,13 +98,15 @@ strong { } ul { - list-style: inside; + list-style-position: inside; + list-style: disc; padding-left: 25px; } ol { - list-style: decimal inside; - padding-left: 20px; + list-style-position: inside; + list-style: decimal; + padding-left: 25px; } blockquote {