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 @@ - +
- + - - - - +Lightweight json library written in C.
-This project is maintained by kgabis
-Parson is a lighweight json parser and reader written in C.
+Parson is a lighweight json library written in C.
-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.
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;
+}
+
-
-
+
+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) {}
-
-