Add /json endpoint and refactor a little bit