text.jsonをリリース
JSONを読み書きするGaucheモジュールを書きました。すでにtrunkにはrfc.jsonというのが入っていて、そう遠くない未来にリリースされると思うんですが*1、まあそれまでのつなぎとして。コードはgithubにあります。
http://github.com/teppey/Gauche-text-json/
インストール
gauche-packageにパッケージのURLを渡すのが簡単です。
$ gauche-package install [-S root] http://github.com/downloads/teppey/Gauche-text-json/Gauche-text-json-0.1.tgz
使用例
$ cat books.json [ { "title": "星を継ぐもの", "author": "J・P・ホーガン", "price": 660 }, { "title": "北壁の死闘", "author": "ボブ・ラングレー", "price": 900 }, { "title": "旅のラゴス", "author": "筒井康隆", "price": 438 } ] $ gosh gosh> (use text.json) #<undef> gosh> (define json (with-input-from-file "./books.json" json-read)) json gosh> (use slib) #<undef> gosh> (require 'pretty-print) #t gosh> (pretty-print json) #((("title" . "星を継ぐもの") ("author" . "J・P・ホーガン") ("price" . 660)) (("title" . "北壁の死闘") ("author" . "ボブ・ラングレー") ("price" . 900)) (("title" . "旅のラゴス") ("author" . "筒井康隆") ("price" . 438))) 21 gosh> (ref json 0) (("title" . "星を継ぐもの") ("author" . "J・P・ホーガン") ("price" . 660)) gosh> (json-write (ref json 0) #f) "{\"title\":\"\\u661F\\u3092\\u7D99\\u3050\\u3082\\u306E\",\"author\":\"J\\u30FBP\\u30FB\\u30DB\\u30FC\\u30AC\\u30F3\",\"price\":660}" gosh> (json-read (json-write (ref json 0) #f)) (("title" . "星を継ぐもの") ("author" . "J・P・ホーガン") ("price" . 660)) gosh>
よかったらお使いください。
*1:追記: 0.9.1で入りました