| 1 |
JSON Module |
| 2 |
|
| 3 |
Matthew Williams |
| 4 |
|
| 5 |
<[email protected]> |
| 6 |
|
| 7 |
Edited by |
| 8 |
|
| 9 |
Matthew Williams |
| 10 |
|
| 11 |
<[email protected]> |
| 12 |
|
| 13 |
Copyright © 2011 Flowroute LLC (flowroute.com) |
| 14 |
__________________________________________________________________ |
| 15 |
|
| 16 |
Table of Contents |
| 17 |
|
| 18 |
1. Admin Guide |
| 19 |
|
| 20 |
1. Overview |
| 21 |
2. Dependencies |
| 22 |
|
| 23 |
2.1. Kamailio Modules |
| 24 |
2.2. External Libraries or Applications |
| 25 |
|
| 26 |
3. Functions |
| 27 |
|
| 28 |
3.1. json_get_field(json_string, field_name, destination) |
| 29 |
3.2. json_get_string(json_string, field_name, destination) |
| 30 |
|
| 31 |
4. Transformations |
| 32 |
|
| 33 |
List of Examples |
| 34 |
|
| 35 |
1.1. json_get_field usage |
| 36 |
1.2. json_get_string usage |
| 37 |
1.3. json.parse usage |
| 38 |
|
| 39 |
Chapter 1. Admin Guide |
| 40 |
|
| 41 |
Table of Contents |
| 42 |
|
| 43 |
1. Overview |
| 44 |
2. Dependencies |
| 45 |
|
| 46 |
2.1. Kamailio Modules |
| 47 |
2.2. External Libraries or Applications |
| 48 |
|
| 49 |
3. Functions |
| 50 |
|
| 51 |
3.1. json_get_field(json_string, field_name, destination) |
| 52 |
3.2. json_get_string(json_string, field_name, destination) |
| 53 |
|
| 54 |
4. Transformations |
| 55 |
|
| 56 |
1. Overview |
| 57 |
|
| 58 |
This is a simple module allowing to retrieve values from a JSON string. |
| 59 |
|
| 60 |
For more complex operations with JSON documents, see the JANSSON |
| 61 |
module. |
| 62 |
|
| 63 |
2. Dependencies |
| 64 |
|
| 65 |
2.1. Kamailio Modules |
| 66 |
2.2. External Libraries or Applications |
| 67 |
|
| 68 |
2.1. Kamailio Modules |
| 69 |
|
| 70 |
The following modules must be loaded before this module: |
| 71 |
* None |
| 72 |
|
| 73 |
2.2. External Libraries or Applications |
| 74 |
|
| 75 |
The following libraries or applications must be installed before |
| 76 |
running Kamailio with this module loaded: |
| 77 |
* libjson (https://github.com/json-c/json-c/wiki) |
| 78 |
|
| 79 |
3. Functions |
| 80 |
|
| 81 |
3.1. json_get_field(json_string, field_name, destination) |
| 82 |
3.2. json_get_string(json_string, field_name, destination) |
| 83 |
|
| 84 |
3.1. json_get_field(json_string, field_name, destination) |
| 85 |
|
| 86 |
Copy field 'field_name' from json object 'json_string' and store it in |
| 87 |
pvar 'destination'. |
| 88 |
|
| 89 |
Note that the result is the string representation of that JSON filed. |
| 90 |
For example, if you want to retrieve a field that has a string value, |
| 91 |
then the result is the value enclosed in quotes. If the field value is |
| 92 |
a structure, then the result is the string-formatted representation of |
| 93 |
that structure. |
| 94 |
|
| 95 |
Example 1.1. json_get_field usage |
| 96 |
... |
| 97 |
json_get_field("{'foo':'bar'}", "foo", "$var(foo)"); |
| 98 |
xlog("foo is $var(foo)"); |
| 99 |
... |
| 100 |
|
| 101 |
3.2. json_get_string(json_string, field_name, destination) |
| 102 |
|
| 103 |
Copy field 'field_name' from json object 'json_string' and store it in |
| 104 |
pvar 'destination'. |
| 105 |
|
| 106 |
Example 1.2. json_get_string usage |
| 107 |
... |
| 108 |
json_get_string("{'foo':'bar'}", "foo", "$var(foo)"); |
| 109 |
xlog("foo is $var(foo)"); |
| 110 |
... |
| 111 |
|
| 112 |
4. Transformations |
| 113 |
|
| 114 |
You can use the transformation to extract values from the json |
| 115 |
structured pseudo-variables |
| 116 |
* json |
| 117 |
Example 1.3. json.parse usage |
| 118 |
... |
| 119 |
# extract value of "Custom-Data" from $rb pseudo-variable and set it to |
| 120 |
$var(Custom-Data) |
| 121 |
$var(Custom-Data) = $(rb{json.parse,Custom-Data}); |
| 122 |
if($var(Custom-Data) != $null) { xlog("L_INFO", "$ci|log|custom d |
| 123 |
ata: $var(Custom-Data) from Request: $rb"); |
| 124 |
} |
| 125 |
... |