Except that you renamed the wrong function.
This function should be VarRefValueToJson, since it takes a VarRef, finds its value(s) and gives you a JSON object representing that.  The previous function (currently VarRefValueToJson) doesn't do anything with JSON, it just prepares a VarRef and qualifies it if needed.