Implement `as_indexed_json` directly in the model (fixes #51)

Fix for Infinite recursion caused by as_indexed_json (#51)

All previous tests pass. No new tests added though.. kind of difficult to test against infinite recursion. Please also have a look at my comment to the commit.