New JSON_DECODE function

We are testing the new functionality here that landed in v16 rc: Asterisk 16 Function_JSON_DECODE - Asterisk Project - Asterisk Project Wiki

This feature is great and it works well for root level JSON objects. However, is there a way to pluck a property multiple levels deep?

Also, is there a way to parse array’s? I didn’t see anything in the tests that would indicate this ability. I also tried a few variations as shown in the older res_json module but didn’t work.

Thanks again for this feature!

cool, now we just need an JSON_ENCODE funktion

@InterLinked is the individual who contributed said functionality.

You should be able to go multiple levels deep by nesting the function calls, which I’ve done successfully.

e.g. ${JSON_DECODE(JSON_DECODE(something,test),foobar)}

Does this not work?

Aha, I didn’t try it that way but yes that will work. A little more difficult to read/follow but it does function so thanks for that.

As far as arrays go, is it possible to parse arrays?

At this time, I don’t believe so. func_json would need to be extended to do that.

Can you give an example of what you are trying to parse and the desired result?

The dream scenario would be to have parsing regular JSON objects work like this:


The above would allow for nesting without having to nest JSON_DECODE calls.

  "path": {
    "to": {
      "elem": "someVar"

The other scenario involving parsing arrays:


The above would allow for nesting to a specific item in an array (in this case the first item in the array)

  "path": {
    "to": {
      "arr": [

Ah, I see what you mean. Yeah, you can’t do this with the module currently unfortunately.

I can keep this in mind, but at the moment this is not on my list of things to look into and I’m somewhat backlogged. If you need these for your business and you’re able to place a feature bounty of this, I can expedite adding some or all of this functionality this month. Otherwise, it may have to wait until I or someone else in the community has the time and interest in adding this. I don’t know what the timeframe on that would be.

As far as JSON_ENCODE, I am not sure if I understand the use case, JSON_DECODE I imagine as typically being used in conjunction with someone like CURL or SHELL to parse API responses, but if there was a reasonable use case for encoding JSON then I suppose that might make some sense too.

Understood. We are only interested in JSON_DECODE. How do we go about placing a bounty in order to fund this project?


Just sent you a direct message with details.

Also, to elaborate on an earlier point, a problem I see with JSON_ENCODE is that with decoding, you’re taking a JSON string and parsing out an element from a logical array, whereas with encoding, you’re doing the reverse. The dialplan doesn’t have any concept of an “array”, so I’m not sure what it would even make sense to encode here.

If you already have an idea about this Mark, I’d be curious to hear.

Ah I see what you are saying, and thanks for the message.

I’m assuming that it is an array of objects to parse (and not a single value array). Sorry about that.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.