Recently I was working with some large JSON responses from an external service. I was parsing the JSON to a Map to work with it. For some internal needs, I needed the Map to be saved as text.
This is where I encountered a problem with
IO.puts. They both
truncate large data structures in the console output. While this may be appreciated in general when dealing with large data, it makes the resulting text an invalid Map and loses data.
Example of the truncation or abbreviation:
That excerpt is pulled directly from the printed output.
Turns out, there are some extra options with
IO.inspect that can help with this.
:limit option being set to
:infinity prevents the truncation problem. It will write out the full Map as text.
2017-11-17 NOTE: A new option in Elixir 1.5.x is
:printable_limit option applies to strings and charlists while
:limit does not.
This is helpful when trying to inspect a large string. The value is specified in bytes.
large_string = MyApp.TestResponses.load_sample_text_file
IO.inspect(large_string, printable_limit: 8192)
There are some additional nice options available as well. Might be worth checking out.