note
kschwab
<p><i>"Does anyone know of a better or more generic way to do these kind of things?"</i></p>
<p>There's lots of choices for config files. JSON and YAML are popular. Your second example is pretty close to JSON already. It would look like this as JSON:</p>
<code>
{
"ObjectType1": {
"Param1": 8,
"Param2": "SomeText",
"NestedObject": {
"Param1": 3,
"Param2": "SomeText"
}
},
"ObjectType2": {
"Param1": 10
}
}
</code>
<p>There are perl modules to parse JSON, some streaming, if you really can't load it all into memory. There's also a really nice command line utility called "jq", see some examples <a href="https://shapeshed.com/jq-json/">here</a>.</p>
<p> Note that JSON doesn't support comments, which is probably the biggest complaint about it as a configuration file format.</p>
1227916
1227916