Skip to content

A simple demonstration of JSON parsing in Ruby, showing string and file handling techniques

Notifications You must be signed in to change notification settings

timeless-residents/handson-ruby-json-parse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Ruby JSON パースのデモ

RubyでJSONを扱う基本的な機能を紹介するデモプログラムです。

機能

  • JSON文字列をRubyのハッシュに変換
  • JSONファイルの読み込みとパース
  • JSONのキーをシンボルに変換
  • 基本的なエラー処理

使い方

  1. Rubyがインストールされていることを確認
  2. data.json ファイルを以下のような内容で作成:
{
  "name": "佐藤",
  "age": 30,
  "hobbies": ["読書", "旅行", "プログラミング"]
}
  1. デモを実行:
ruby main.rb

コード例

require 'json'

# JSON文字列をパース
json_string = '{"name": "田中", "age": 25}'
result = JSON.parse(json_string)

# JSONファイルをパース
if File.exist?("data.json")
  File.open("data.json") do |file|
    data = JSON.parse(file.read)
    # データを処理
  end
end

必要条件

  • Ruby(最新の安定版推奨)
  • JSONライブラリ(Ruby標準ライブラリに含まれています)

ライセンス

MIT

About

A simple demonstration of JSON parsing in Ruby, showing string and file handling techniques

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages