<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19983">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">func_json: Fix JSON parsing issues.<br><br>Fix issue with returning empty instead of dumping<br>the JSON string when recursing.<br><br>Also adds a unit test to capture this fix.<br><br>ASTERISK-30441 #close<br><br>Change-Id: If0bde9f3fe84f7af485e0838205cc21e0f752a85<br>---<br>M funcs/func_json.c<br>1 file changed, 22 insertions(+), 1 deletion(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/funcs/func_json.c b/funcs/func_json.c</span><br><span>index 6672c58..8bfcd4c 100644</span><br><span>--- a/funcs/func_json.c</span><br><span>+++ b/funcs/func_json.c</span><br><span>@@ -174,7 +174,11 @@</span><br><span>                              previouskey = currentkey;</span><br><span>                            currentkey = strsep(key, nestchar); /* retrieve the desired index */</span><br><span>                                 ast_debug(1, "Recursing on object (key was '%s' and is now '%s')\n", previouskey, currentkey);</span><br><span style="color: hsl(0, 100%, 40%);">-                                if (parse_node(key, currentkey, nestchar, count, ast_json_object_get(jsonval, currentkey), buf, len, depth)) { /* recurse on this node */</span><br><span style="color: hsl(120, 100%, 40%);">+                             if (!currentkey) { /* this is the end, so just dump the object */</span><br><span style="color: hsl(120, 100%, 40%);">+                                     char *result2 = ast_json_dump_string(jsonval);</span><br><span style="color: hsl(120, 100%, 40%);">+                                        ast_copy_string(buf, result2, len);</span><br><span style="color: hsl(120, 100%, 40%);">+                                   ast_json_free(result2);</span><br><span style="color: hsl(120, 100%, 40%);">+                               } else if (parse_node(key, currentkey, nestchar, count, ast_json_object_get(jsonval, currentkey), buf, len, depth)) { /* recurse on this node */</span><br><span>                                     return -1;</span><br><span>                           }</span><br><span>                    }</span><br><span>@@ -305,6 +309,7 @@</span><br><span>              {"{ \"path\": { \"to\": { \"arr\": [ {\"name\": \"John Smith\", \"phone\": \"123\"}, {\"name\": \"Jane Doe\", \"phone\": \"234\"} ] } } }", ",c", "path.to.arr.0.name", "John Smith"},</span><br><span>                 {"{ \"path\": { \"to\": { \"arr\": [ {\"name\": 1, \"phone\": 123}, {\"name\": 2, \"phone\": 234} ] } } }", ",c", "path.to.arr.0.name", "1"},</span><br><span>          {"{ \"path\": { \"to\": { \"arr\": [ {\"name\": [ \"item11\", \"item12\" ], \"phone\": [ \"item13\", \"item14\" ]}, {\"name\": [ \"item15\", \"item16\" ], \"phone\": [ \"item17\", \"item18\" ]} ] } } }", ",c", "path.to.arr.0.name.1", "item12"},</span><br><span style="color: hsl(120, 100%, 40%);">+            {"{ \"startId\": \"foobar\", \"abcd\": { \"id\": \"abcd\", \"type\": \"EXT\" }, \"bcde\": { \"id\": \"bcde\", \"type\": \"CONDITION\" }, \"defg\": { \"id\": \"defg\", \"type\": \"EXT\" }, \"efgh\": { \"id\": \"efgh\", \"type\": \"VOICEMAIL\" } }", "", "bcde", "{\"id\":\"bcde\",\"type\":\"CONDITION\"}"},</span><br><span>         };</span><br><span> </span><br><span>       switch (cmd) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19983">change 19983</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19983"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: If0bde9f3fe84f7af485e0838205cc21e0f752a85 </div>
<div style="display:none"> Gerrit-Change-Number: 19983 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>