Ruby on Rails #105 parse JSON and YAML

25/01/2023 (about 1 year ago)
yaml json data parsing

JSON and YAML are great ways of storing data structures.
You can parse a JSON/YAML file directly with Ruby, or within a Rails application.
You can also WRITE to the file!

Popular usecases:

  • parse file and create seed data
  • display parsed default data directly in a view (for example FAQ section)

Episode source code:

Parse JSON with Ruby on Rails:
Parse YAML with Ruby on Rails:

0:00 incoming JSON and YAML data
0:50 parse YAML with Ruby (no Rails)
2:01 update and save YAML file
3:01 parse JSON with Ruby (no Rails)
3:50 display YAML in Rails controller
6:05 display JSON in Rails controller
6:37 seed database data from datafile

Sign in to join the conversation