ref-refactoring: re-implement JSON decoding