variable_dict_from_file_type

Define a variable that contains key,value pairs (a dictionary) from a JSON, CSV or YAML file.

⚙️ Compatible targets: Linux

Parameters

NameDocumentation
prefixThe prefix of the variable name.

This parameter is required.
nameThe variable to define, the full name will be prefix.name.

This parameter is required.
file_nameThe file name to load data from.

This parameter is required.
file_typeThe file type, can be "JSON", "CSV", "YAML" or "auto" for auto detection based on file extension, with a fallback to JSON (default is "auto").

Choices:
  • auto
  • JSON
  • YAML
  • CSV

This parameter is optional.

Outcome conditions

You need to replace ${name} with its actual canonified value.

  • ✅ Ok: variable_dict_from_file_type_${name}_ok
    • ☑️ Already compliant: variable_dict_from_file_type_${name}_kept
    • 🟨 Repaired: variable_dict_from_file_type_${name}_repaired
  • ❌ Error: variable_dict_from_file_type_${name}_error

Example

method: variable_dict_from_file_type
params:
  name: VALUE
  file_name: VALUE
  prefix: VALUE
  file_type: auto

Documentation

To use the generated variable, you must use the form ${prefix.name[key]} with each name replaced with the parameters of this method.

Be careful that using a global variable can lead to unpredictable content in case of multiple definition, which is implicitly the case when a technique has more than one instance (directive).

This method will load data from various file formats (yaml, json, csv).

CSV parsing

The input file must use CRLF as line delimiter to be readable (as stated in RFC 4180).

Examples

# To read a json file with format auto detection 
variable_dict_from_file_type("prefix", "var", "/tmp/file.json", "");
# To force yaml reading on a non file without yaml extension
variable_dict_from_file_type("prefix", "var", "/tmp/file", "YAML");

If /tmp/file.json contains:

{
  "key1": "value1"
}

You will be able to access the value1 value with ${prefix.var[key1]}.