refactor json processing code