Here is an example with a Json dictionary.
    
    
    import json
    
    {.experimental: "dotOperators".}
    
    type
      Action = ref object
        properties: JsonNode
    
    template `.`(action: Action, field: untyped): untyped =
      action.properties[astToStr(field)]
    
    template `.=`(action: Action, field, value: untyped): untyped =
      action.properties[astToStr(field)] = %value
    
    var a = Action(
      properties: %*{
        "layer": 0,
        "add": true,
        "vis": false,
        "new_name": "fancy_name"
      }
    )
    
    echo a.new_name # "fancy_name"
    
    a.algo = 10
    echo a.algo     # 10
    
    
    Run

You can store and deserialize more complex types as strings with the [marshal 
module](https://nim-lang.org/docs/marshal.html) or as JsonNode with the [to 
macro in JSON 
module](https://nim-lang.org/docs/json.html#to.m%2CJsonNode%2Ctypedesc)

Reply via email to