Last night I pushed an updated json module to branch mgw/json. It has significant improvements over the previous version, including:<div><br></div><div>* A way to access nested elements, using a subset of JSONPath.</div><div>
* The ability to loop over arrays<br>
<div><br></div><div>Note that there is a change in the external dependency from libjson-c to libjansson.</div><div><br></div><div>Matthew Williams</div><div><br></div><div><br></div><div><br></div><div>Documentation:</div>
<div><br></div><div><br></div><div><div>JSON Module</div><div><br></div><div>Joe Hillenbrand</div><div><br></div><div> <<a href="mailto:joe@flowroute.com">joe@flowroute.com</a>></div><div><br></div><div>Edited by</div>
<div><br></div><div>Matthew Williams</div><div><br></div><div> <<a href="mailto:matthew@flowroute.com">matthew@flowroute.com</a>></div><div><br></div><div> Copyright © 2013 Flowroute LLC (<a href="http://flowroute.com">flowroute.com</a>)</div>
<div> __________________________________________________________________</div><div><br></div><div> Table of Contents</div><div><br></div><div> 1. Admin Guide</div><div><br></div><div> 1. Overview</div><div>
2. Dependencies</div><div><br></div><div> 2.1. Kamailio Modules</div><div> 2.2. External Libraries or Applications</div><div><br></div><div> 3. Parameters</div><div><br></div><div>
3.1.</div><div><br></div><div> 4. Functions</div><div><br></div><div> 4.1. json_path_get(json_string, json_path, destination)</div><div> 4.2. json_array_size(json_string, json_path, destination)</div>
<div> 4.3. json_get_field(json_string, field_name, destination)</div><div><br></div><div> List of Examples</div><div><br></div><div> 1.1. json_path_get usage</div><div> 1.2. json_array_size usage</div><div>
1.3. json_get_field usage</div><div><br></div><div>Chapter 1. Admin Guide</div><div><br></div><div> Table of Contents</div><div><br></div><div> 1. Overview</div><div> 2. Dependencies</div><div><br></div><div> 2.1. Kamailio Modules</div>
<div> 2.2. External Libraries or Applications</div><div><br></div><div> 3. Parameters</div><div><br></div><div> 3.1.</div><div><br></div><div> 4. Functions</div><div><br></div><div> 4.1. json_path_get(json_string, json_path, destination)</div>
<div> 4.2. json_array_size(json_string, json_path, destination)</div><div> 4.3. json_get_field(json_string, field_name, destination)</div><div><br></div><div>1. Overview</div><div><br></div><div> This module provides operations on json strings.</div>
<div><br></div><div>2. Dependencies</div><div><br></div><div> 2.1. Kamailio Modules</div><div> 2.2. External Libraries or Applications</div><div><br></div><div>2.1. Kamailio Modules</div><div><br></div><div> The following modules must be loaded before this module:</div>
<div> * None</div><div><br></div><div>2.2. External Libraries or Applications</div><div><br></div><div> The following libraries or applications must be installed before</div><div> running Kamailio with this module loaded:</div>
<div> * jansson (<a href="http://www.digip.org/jansson/">http://www.digip.org/jansson/</a>), tested with: 2.2+</div><div><br></div><div>3. Parameters</div><div><br></div><div> 3.1.</div><div><br></div><div> None</div>
<div><br></div><div>4. Functions</div><div><br></div><div> 4.1. json_path_get(json_string, json_path, destination)</div><div> 4.2. json_array_size(json_string, json_path, destination)</div><div> 4.3. json_get_field(json_string, field_name, destination)</div>
<div><br></div><div>4.1. json_path_get(json_string, json_path, destination)</div><div><br></div><div> Copy the value at the path from json object 'json_string' and store it</div><div> in pvar 'destination'.</div>
<div><br></div><div> The path string supports dot delimited notation (e.g. foo.bar.baz),</div><div> array notation (e.g. list[0]), or a combination of the two (e.g.</div><div> foo.bar[0][1].baz).</div><div><br></div>
<div> The function can put a string, integer, null, or new json string into</div><div> destination.</div><div><br></div><div> Example 1.1. json_path_get usage</div><div>...</div><div>json_path_get($var(myjson), "inner.deep.num", "$var(n)");</div>
<div>xlog("foo is $var(n)");</div><div>...</div><div><br></div><div>4.2. json_array_size(json_string, json_path, destination)</div><div><br></div><div> Puts size of the array in 'json_string' at 'json_path' into the pvar</div>
<div> 'destination'.</div><div><br></div><div> This is particularly useful for looping through an array. See example.</div><div><br></div><div> Example 1.2. json_array_size usage</div><div>...</div><div>$var(array) = "{\"loopme\":[0,1,2,3,4,5]}";</div>
<div>$var(count) = 0;</div><div>json_array_size($var(array), "loopme", "$var(size)");</div><div>while($var(count) < $var(size)) {</div><div> json_path_get($var(array), "loopme[$var(count)]", "$var(v)");</div>
<div> xlog("loopme[$var(count)] == $var(v)\n");</div><div> $var(count) = $var(count) + 1;</div><div>}</div><div>...</div><div><br></div><div>4.3. json_get_field(json_string, field_name, destination)</div>
<div><br></div><div> Copy field 'field_name' from json object 'json_string' and store it in</div><div> pvar 'destination'.</div><div><br></div><div> This function is deprecated but kept for backwards compatibility. Right</div>
<div> now it is just a wrapper around json_path_get, and its functionality is</div><div> the same.</div><div><br></div><div> Example 1.3. json_get_field usage</div><div>...</div><div>json_get_field("{'foo':'bar'}", "foo", "$var(foo)");</div>
<div>xlog("foo is $var(foo)");</div><div>...</div></div></div>