Skip to content

Commit 28391e8

Browse files
chore(docs): update json examples (#4120)
Fixing some typos and updated doc with implemented feature (struct from json) ## Checklist - [ ] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
1 parent a8e0ecb commit 28391e8

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

docs/docs/07-examples/06-json.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ log("${jsonHomogeneousArrayValue}");
3535
```js playground
3636
let x: num = 42;
3737
let jsonNum = Json x;
38-
log("${j}"); // 42
38+
log("${jsonNum}"); // 42
3939

4040
let chars = Array<str>["a", "b"];
4141
let jsonChars = Json chars;
42-
log("${chars}"); // ["a","b"]
42+
log("${jsonChars}"); // ["a","b"]
4343

4444
let jsonComplex = Json { "first": x, "second": chars };
4545
log("${jsonComplex}"); // {"first": 42, "second": ["a","b"]}
@@ -115,4 +115,17 @@ let j = Json {
115115
log(j.get("k").asBool());
116116
```
117117

118-
Future support for converting to structs and other types: [#2188](https://github.com/winglang/wing/issues/2118)
118+
## Safely convert to structs
119+
```js playground
120+
struct Foo {
121+
val1: str;
122+
val2: num;
123+
}
124+
125+
let jFoo = {
126+
val1: "cool",
127+
val2: 21
128+
};
129+
130+
let foo = Foo.fromJson(jFoo);
131+
```

0 commit comments

Comments
 (0)