Modified the to_json method to offer pretty_print option.