Paste: Serialising and deserliasing JSON representation

Author: Loryn Jenkins
Mode: factor
Date: Thu, 11 Jul 2013 06:36:36
Plain Text |
TUPLE: cd
    { title string } 
    { artist string }
    { rating number }
    { ripped boolean } ;

C: <cd> cd 

: save-as-json ( obj filename -- )
    [ >json ] dip utf8 set-file-contents ;
    
: read-from-json ( filename -- array )
    utf8 file-contents json> ;
    
: hashtable>cd ( hashtable -- cd )
    >alist 
    cd "slots" word-prop [ name>> ] map
    [ dupd of ] map nip 
    first4 cd boa ;

: load-cd-db ( -- )
    P" /Users/loryn/json-db-cd-collection" read-from-json
    make-db [ hashtable>cd db-add ] each ;

New Annotation

Summary:
Author:
Mode:
Body: