Skip to content

Instantly share code, notes, and snippets.

@mckomo
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckomo/debe8bb6596276a3d033 to your computer and use it in GitHub Desktop.
Save mckomo/debe8bb6596276a3d033 to your computer and use it in GitHub Desktop.
Liquid filter suited for Jekyll that generates pretty JSON output.
module Jekyll
module PrettyJsonFilter
def pretty_json(input)
begin
JSON.pretty_generate(input)
rescue JSON::GeneratorError => e
"Error: #{e}."
end
end
end
end
Liquid::Template.register_filter(Jekyll::PrettyJsonFilter)
# USAGE:
# {{ site.data.user | pretty_json }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment