Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Created May 14, 2020 18:32
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 blairanderson/48feba92981b2ffd81c2b1556e0edd01 to your computer and use it in GitHub Desktop.
Save blairanderson/48feba92981b2ffd81c2b1556e0edd01 to your computer and use it in GitHub Desktop.
write JSON file data to multiple files [ruby]
require 'active_support'
require 'active_support/core_ext'
require 'json'
JSON.parse(File.open("./_data/companies.json").read).each do |company|
File.open("./_companies/#{company['name'].parameterize}.md", "w") do |f|
f.write "---\n"
f.write "layout: company\n"
f.write "title: #{company['name']}\n"
f.write "categories: prep\n"
f.write "website: '#{company['website']}'\n"
f.write "location: #{company['location']}\n"
f.write "---\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment