File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -4,16 +4,23 @@ title: validdata
4
4
published : true
5
5
---
6
6
7
- [ %CFEngine_function_prototype(data_container, type)%]
7
+ [ %CFEngine_function_prototype(data_container, type, strict )%]
8
8
9
9
** Description:** Validates a JSON container from ` data_container ` and returns
10
- ` true ` if the contents are valid JSON.
10
+ ` "true" ` if the contents are valid JSON.
11
+ An optional second argument ` strict ` may be used to enable strict validation.
12
+ When set to ` "true" ` the function will not evaluate to true for JSON primitives.
13
+ The default value of ` strict ` is ` "false" ` .
14
+
15
+ The strict behavior matches the expectations in other parts of policy language.
16
+ Notably, ` data ` containers and functions like ` readjson() ` and ` parsejson() ` expect JSON containers (arrays and objects) not primitives.
17
+ Thus, using ` validdata() ` with ` strict ` set to ` "true" ` is an effective way to check if something can be parsed by those functions.
11
18
12
19
This function is intended to be expanded with functionality for validating
13
20
CSV and YAML files eventually, mirroring ` readdata() ` . If ` type ` is ` JSON ` ,
14
21
it behaves the same as ` validjson() ` .
15
22
16
- [ %CFEngine_function_attributes(data_container, type)%]
23
+ [ %CFEngine_function_attributes(data_container, type, strict )%]
17
24
18
25
** Example:**
19
26
Original file line number Diff line number Diff line change @@ -4,12 +4,19 @@ title: validjson
4
4
published : true
5
5
---
6
6
7
- [ %CFEngine_function_prototype(string)%]
7
+ [ %CFEngine_function_prototype(string, strict )%]
8
8
9
9
** Description:** Validates a JSON container from ` string ` and returns
10
- ` true ` if the contents are valid JSON.
10
+ ` "true" ` if the contents are valid JSON.
11
+ An optional second argument ` strict ` may be used to enable strict validation.
12
+ When set to ` "true" ` the function will not evaluate to true for JSON primitives.
13
+ The default value of ` strict ` is ` "false" ` .
11
14
12
- [ %CFEngine_function_attributes(string)%]
15
+ The strict behavior matches the expectations in other parts of policy language.
16
+ Notably, ` data ` containers and functions like ` readjson() ` and ` parsejson() ` expect JSON containers (arrays and objects) not primitives.
17
+ Thus, using ` validjson() ` with ` strict ` set to ` "true" ` is an effective way to check if something can be parsed by those functions.
18
+
19
+ [ %CFEngine_function_attributes(string, strict)%]
13
20
14
21
** Example:**
15
22
You can’t perform that action at this time.
0 commit comments