fixing recursive function for extended JSON to correctly handle arrays