extends JSONProperty
returns: Dictionary
Only allows strings representing a path to a JSON configuration file. This path can be absolute or relative. When the file path is relative, it would be relative to the directory that contains the JSON configuration file that specifies this field. Please, use '/' as a path delimiter.
Once you have instantiated the 'JSONPropertyJSONConfigFile' class, you must determine which JSONConfigFile this property would use via the 'set_json_config_file' method.
In this example, the configuration structure has one required property. The property 'json_file' must be a path to another JSON configuration file that must contain a 'number' property.
# Create a JSON configuration file
var json_config_file = JSONConfigFile.new()
# Create another JSON configuration file
var number_file = JSONConfigFile.new()
# Add a 'number' property, which must be a number
number_file.add_property("number", JSONPropertyNumber.new())
# Create a JSON configuration file property
var json_property = JSONPropertyJSONConfigFile.new()
# Set its JSON configuration file to the one created previously
json_property.set_json_config_file(number_file)
# Add the 'json_file' property, which is a path to another JSON configuration file
json_config_file.add_property("json_file", json_property)
# Validate input
json_config_file.validate(json_file_path)This JSON has the required field, and also the JSON it points to.
{
"json_file": "json_path.json"
}This is the content of 'json_path.json':
{
"number": 42
}This JSON contains one error. The 'json_file' property is not the correct type.
{
"json_file": 42
}Returned error:
[
{
"error": JSONProperty.Errors.WRONG_TYPE,
"expected": JSONProperty.Types.JSON_CONFIG_FILE,
"context": "json_file",
"as_text": "Wrong type: expected 'JSON configuration file path', at 'json_file'."
}
]This JSON contains one error. The 'json_file' property indicates a path to a file that does not exist.
{
"json_file": "missing_json_path.json"
}Returned error:
[
{
"error": JSONProperty.Errors.COULD_NOT_OPEN_FILE,
"code": ERR_FILE_NOT_FOUND,
"context": "json_file",
"as_text": "Could not open the file, at 'json_file'."
}
]This JSON has the required field, but not the JSON it points to.
{
"json_file": "json_path.json"
}This is the content of 'json_path.json':
{
"number": "Not a number"
}Returned error:
[
{
"error": JSONProperty.Errors.WRONG_TYPE,
"expected": JSONProperty.Types.NUMBER,
"context": "json_file.number",
"as_text": "Wrong type: expected 'number', at 'json_file.number'."
}
]The public methods of this class are:
| Name | Params | Description | Returns |
|---|---|---|---|
| set_preprocessor | processor -> JSONConfigProcessor: Object that defines the function to execute before the validation process. |
Sets the process to execute before the validation process. | Nothing. |
| set_postprocessor | processor -> JSONConfigProcessor: Object that defines the function to execute after the validation process. |
Sets the process to execute after the validation process. | Nothing. |
| set_json_config_file | json_config_file -> JSONConfigFile: Object that would validate the file indicated by the path that this field contains. |
Sets the JSON Configuration File. | Nothing. |
This class could directly raise any of the following errors:
| Enum value | Description | Params | As text |
|---|---|---|---|
| WRONG_TYPE | The type of the input does not match the expected one. | expected -> int: Takes the value JSON_CONFIG_FILE. |
Wrong type: expected 'JSON configuration file path' |