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:Start of change
	tpf_doc_addElement(“a”,”1”);
	tpf_doc_addElement(“b[0]”,”1”);
	tpf_doc_addElement(“b[1]”,”2”);
	tpf_doc_addElement(“$.c[0].d”,”1”);
End of changeThis JSON document is created:Start of change
{“a”:1,“b”:[1,2],“c”:[{“d”:1}] }
End of change
You also can use the tpf_doc_addElement function with the tpf_doc_appendElement function to create a JSON document:Start of change
	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”)
	
End of changeThis JSON document is created: Start of change
{ “aˮ : 1, “bˮ : [1,2], “cˮ: [{“dˮ:1,“eˮ:2}] }
End of change

Get element API example

This JSON document is used in the following examples:Start of change
{ “aˮ : 1, “bˮ : [1, 2], “cˮ: [{“dˮ:1}] }
End of change
The following sequence of using the tpf_doc_getElement function retrieves the expected values:Start of change
	tpf_doc_getElement(“$.a”)  = “1”
	tpf_doc_getElement(“b[0]”) = “1”
	tpf_doc_getElement(“b[1]”) = “2”
	tpf_doc_getElement(“c[0].d”) = “1”
End of change
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;