Rewrote iteration of JSON data

Restructured code and changed to use stdin/stdout instead of files