CORE-3491: added a general JSON decoding function for either strings or streams