Skip to content

Commit cded73a

Browse files
authored
Merge pull request #336 from d4v1d03/main
added JSON data validation faq
2 parents ccb4852 + 2f4f072 commit cded73a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/user_docs/support/faq-kcl.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,3 +2550,40 @@ final_list:
25502550
## 61. What does `version: "v1" = "v1"` mean?
25512551

25522552
The first `"v1"` over here denotes that the type of the variable `version` is of string literal type. The second `"v1"` denotes that the default value of the variable `version` is `"v1"`.
2553+
2554+
## 62. How do i define a schema to verify the contents of a given JSON file?
2555+
2556+
We can use the kcl `vet` tool to validate the JSON data in a given JSOn file. For example, in the below data.json file we use the KCL file(schema.k) below to validate the `age` parameter.
2557+
2558+
data.json
2559+
2560+
```json
2561+
[
2562+
{
2563+
"name": "Alice",
2564+
"age": 18
2565+
},
2566+
{
2567+
"name": "Bob",
2568+
"age": 10
2569+
}
2570+
]
2571+
```
2572+
2573+
schema.k
2574+
2575+
```kcl
2576+
schema Person:
2577+
name: str
2578+
age: int
2579+
2580+
check:
2581+
age >= 10
2582+
```
2583+
2584+
The command to validate the JSON data below gives the output `Validate success!`.
2585+
2586+
```bash
2587+
kcl vet data.json schema.k
2588+
```
2589+

0 commit comments

Comments
 (0)