You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user_docs/support/faq-kcl.md
+37Lines changed: 37 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2550,3 +2550,40 @@ final_list:
2550
2550
## 61. What does `version: "v1" = "v1"` mean?
2551
2551
2552
2552
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!`.
0 commit comments