Get and add element API examples
You can use the tpf_doc_getElement and tpf_doc_addElement functions to retrieve values from a JSON document and create a JSON document.
Add element API examples
The following sequence of using the tpf_doc_addElement function creates a JSON
document:
This JSON document is
created:


tpf_doc_addElement(“a”,”1”);
tpf_doc_addElement(“b[0]”,”1”);
tpf_doc_addElement(“b[1]”,”2”);
tpf_doc_addElement(“$.c[0].d”,”1”);
This JSON document is
created:
{“a”:1,“b”:[1,2],“c”:[{“d”:1}] }
You also can use the tpf_doc_addElement function with
the tpf_doc_appendElement function to create a JSON
document:
This JSON document is created:



tpf_doc_addElement(“a”,”1”);
tpf_doc_addElement(“b[0]”,”1”);
tpf_doc_addElement(“b[1]”,”2”);
tpf_doc_addElement(“$.c[0].d”,”1”)
tpf_doc_appendElement(“c[0]”“e”,”2”)
This JSON document is created:

{ “aˮ : 1, “bˮ : [1,2], “cˮ: [{“dˮ:1,“eˮ:2}] }
Get element API example
This JSON document is used in the following
examples:


{ “aˮ : 1, “bˮ : [1, 2], “cˮ: [{“dˮ:1}] }
The following sequence of using the tpf_doc_getElement function retrieves the expected
values:


tpf_doc_getElement(“$.a”) = “1”
tpf_doc_getElement(“b[0]”) = “1”
tpf_doc_getElement(“b[1]”) = “2”
tpf_doc_getElement(“c[0].d”) = “1”
You also can use the tpf_doc_getElement function with
the tpf_doc_getNextElement function to retrieve the
values:
tpf_doc_getElement(“b”) = NULL
tpf_doc_getNextElement() → b[0] = “1”
tpf_doc_getNextElement() → b[1] = “2”
tpf_doc_getNextElement() → c = NULL
tpf_doc_getNextElement() → c[0] = NULL
tpf_doc_getNextElement() → d = 1;