dictknifeでtomlをサポートしてみることにした

github.com

loadingの部分を少しだけ整理した。ついでにtomlもサポートすることにしてみた。 concatで変換が行えて便利。

fruits.json

{
  "fruit": [
    {
      "name": "apple",
      "physical": {
        "color": "red",
        "shape": "round"
      },
      "variety": [
        { "name": "red delicious" },
        { "name": "granny smith" }
      ]
    },
    {
      "name": "banana",
      "variety": [
        { "name": "plantain" }
      ]
    }
  ]
}

これをtomlとyamlに変換する。

$ dictknife concat fruits.json --dst fruits.yaml
$ dictknife concat fruits.json --dst fruits.toml

fruits.yaml

fruit:
- name: apple
  physical:
    color: red
    shape: round
  variety:
  - name: red delicious
  - name: granny smith
- name: banana
  variety:
  - name: plantain

fruits.toml

[[fruit]]
name = "apple"
[[fruit.variety]]
name = "red delicious"
[[fruit.variety]]
name = "granny smith"
[fruit.physical]
color = "red"
shape = "round"
[[fruit]]
name = "banana"
[[fruit.variety]]
name = "plantain"