I know we shouldn’t be using Asterisk 13 but its for a legacy app and need some suggestion here. We are making an API call and lets say it returns following JSON -
Write an AGI in a language you are comfortable with that has a JSON parsing library.
Write a Bash script and execute it with the SHELL function. You could just grep for the bits you want or use ‘jq’ to actually parse and return the bits. Using jq would be much less fragile.
I would do it as an AGI, because, well, for a lot of reasons
However, here’s a shell script example:
extensions.conf:
; test.sh parsing JSON
same = n, set(json={\"status\": true,\"name\":{\"businessname\": \"baba black sheep\",\"housename\":\"johny johny\"},\"anotherstring\": \"Hell$
same = n, set(bits=${SHELL(/var/lib/asterisk/agi-bin/test.sh "${json}")})
same = n, verbose(1,The extracted bits are ${bits})
same = n, hangup()
test.sh:
#!/bin/bash
# save the json to a variable
json="$1"
# parse the bits we need from the json
anotherstring=$(jq .anotherstring <<<"${json}")
businessname=$(jq .name.businessname <<<"${json}")
housename=$(jq .name.housename <<<"${json}")
# return the bits in a formatted string
printf '%s<44443@%s;cp=%s>'\
"${businessname}"\
"${housename//\"}"\
"${anotherstring//\"}"
# (end of test.sh)