Skip to content

added JSON data validation faq #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions docs/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2550,3 +2550,40 @@ final_list:
## 61. What does `version: "v1" = "v1"` mean?

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"`.

## 62. How do i define a schema to verify the contents of a given JSON file?

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.

data.json

```json
[
{
"name": "Alice",
"age": 18
},
{
"name": "Bob",
"age": 10
}
]
```

schema.k

```kcl
schema Person:
name: str
age: int

check:
age >= 10
```

The command to validate the JSON data below gives the output `Validate success!`.

```bash
kcl vet data.json schema.k
```