Issue #113. Write to json file properly.

Uses incorrect counter value.