Encoding to json and file writer/reader