Since YAML is a superset of JSON, you can use 
[NimYAML](http://forum.nim-lang.org///nimyaml.org) to deserialize the JSON 
file. It is able to automatically map a JSON object to a Nim object:
    
    
    import yaml.serialization, streams
    
    type Config = object
      rootDev: string
      grubDevLabel: string
      title: string
      updateGrubDir: string
    
    proc readConfig(): Config =
      var s = newStringStream("""
    {
      "rootDev": "rootDevValue",
      "grubDevLabel": "gdlValue",
      "title": "titleValue",
      "updateGrubDir": "ugdValue"
    }
      """)
      load(s, result)
    
    let config = readConfig()
    

To load a file, simply use a `FileStream` instead of a `StringStream`. Note 
that the names of the object's fields must match exactly.

Reply via email to