File tree Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Expand file tree Collapse file tree 1 file changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -35,11 +35,11 @@ log("${jsonHomogeneousArrayValue}");
35
35
``` js playground
36
36
let x: num = 42 ;
37
37
let jsonNum = Json x;
38
- log (" ${j }" ); // 42
38
+ log (" ${jsonNum }" ); // 42
39
39
40
40
let chars = Array < str> [" a" , " b" ];
41
41
let jsonChars = Json chars;
42
- log (" ${chars }" ); // ["a","b"]
42
+ log (" ${jsonChars }" ); // ["a","b"]
43
43
44
44
let jsonComplex = Json { " first" : x, " second" : chars };
45
45
log (" ${jsonComplex}" ); // {"first": 42, "second": ["a","b"]}
@@ -115,4 +115,17 @@ let j = Json {
115
115
log (j .get (" k" ).asBool ());
116
116
```
117
117
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
+ ```
You can’t perform that action at this time.
0 commit comments