Skip to content

Commit d6cdb3b

Browse files
dict & schema conversion faq added
Signed-off-by: Abhishek Kumar <abhishek22512@gmail.com>
1 parent dbce834 commit d6cdb3b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/user_docs/support/faq-kcl.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,3 +2474,22 @@ schema EndPoint:
24742474
schema Gateway:
24752475
attr: str
24762476
```
2477+
2478+
## 57. How to convert dict and schema within kcl?
2479+
2480+
In KCL, dict is a dynamic data that does not have the check constraint of a schema. We can convert dict to a schema to obtain constraints. We can directly assign dict data to schema type data, and KCL runtime will automatically complete type conversion and perform type checking.
2481+
2482+
```shell
2483+
schema Person:
2484+
name: str
2485+
age: int
2486+
2487+
check:
2488+
age > 20
2489+
2490+
config = {
2491+
name = "Alice"
2492+
age = 25
2493+
}
2494+
alice: Person = config
2495+
```

0 commit comments

Comments
 (0)