Faster implementation of fromJSONstat