One of the datatypes somewhere in the structure you're passing into jsonEncode is more than likely not a real dict/list type and jsonEncode barfs on them. There was a recent forum discussion about this failure symptom.
This is a problem with duck-typing languages in general. As I put it to my colleague, something in the structure can walk like a duck and quack like a duck, and has been passing as a duck for a very long time, but when I asked it to lay an egg it fell over and died.