You shouldn't need to rely on the OS echo
command when Elixir IO
already ties into STDOUT. I think you may be getting into trouble here because you are sending the result of IO.inspect
AND the result of IO.puts
(wrapped in the system's echo
command) to STDOUT
, so it's doubling things up and at a minimum, this is confusing, but it probably is invalid as well.
This works for me, given a simple github.json
file containing
{
"sha": "d25341478381063d1c76e81b3a52e0592a7c997f",
"commit": {
"author": {
"name": "Stephen Dolan",
"email": "mu@netsoc.tcd.ie",
"date": "2013-06-22T16:30:59Z"
}
},
"url": "https://api.github.com/repos/stedolan/jq/commits/d25341478381063d1c76e81b3a52e0592a7c997f"
}
stored alongside a parse.exs
script with the following:
contents = File.read!("github.json")
map = Jason.decode!(contents)
json_str = Jason.encode!(map)
IO.puts(json_str)
This decoding and encoding is demonstrates that this is working (substitute Poison
or whatever as desired).
Now, I can run the following command via mix run parse.exs
and I see the expected result. I can also pipe the output as expected, e.g. to jq
:
❯ mix run parse.exs | jq '.sha'
"d25341478381063d1c76e81b3a52e0592a7c997f"