New implementation of toJSONstat