Stratify Object Notation Documentation

Introduction

Stratify Object Notation (SON) is an object storage file format similar to JSON but optimized for use on systems with limited resources (e.g. microcontrollers).

The following JSON data can easily be created in SON format.

{
"float0": 0.5,
"str0": "Hello World",
"object0" : { "number": 1 },
"array0" : [
"unsigned0": 10,
"unsigned1": 50
]
"bool0": true,
"bool1": false
}

Here is the code to create the above data in SON format.

#include "son.h"
void create_data_file(){
//the stack size needs to exceed the depth
//of the data (depth in the example above is 2)
son_stack_t stack[4];
son_t h;
son_create(&h, "/home/data.son", stack, 4);
son_open_obj(&h, ""); //create the root object
son_write_float(&h, "float0", 0.5);
son_write_str(&h, "str0", "Hello World");
son_open_obj(&h, "object0");
son_write_num(&h, "number", 1);
son_open_array(&h, "array0");
son_write_unum(&h, "0", 10); //inside arrays -- keys don't matter
son_write_unum(&h, "1", 50);
son_write_true(&h, "bool0");
son_write_false(&h, "bool1");
son_close_obj(&h); //close root -- calling this is optional, all objects/arrays will close on son_close()
son_close(&h);
}

The data in SON files can be accessed using an access string. Keys are separated by periods and array values are accessed using brackets. The following code shows how to access each value of the above example.

#include "son.h"
void read_values(){
son_t h;
son_open(&h, "/home/data.son");
float float0 = son_read_float(&h, "float0");
char str0[32];
son_read_str(&h, "str0", str0, 32);
int number = son_read_num(&h, "object0.number");
unsigned int array0_0 = son_read_unum(&h, "array0[0]");
unsigned int array0_1 = son_read_unum(&h, "array0[1]");
int bool0 = son_read_bool(&h, "bool0");
int bool1 = son_read_bool(&h, "bool1");
}