Skip to content

Commit

Permalink
chore(docs): update json examples (#4120)
Browse files Browse the repository at this point in the history
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)*.
  • Loading branch information
hasanaburayyan authored Sep 8, 2023
1 parent a8e0ecb commit 28391e8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions docs/docs/07-examples/06-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ log("${jsonHomogeneousArrayValue}");
```js playground
let x: num = 42;
let jsonNum = Json x;
log("${j}"); // 42
log("${jsonNum}"); // 42

let chars = Array<str>["a", "b"];
let jsonChars = Json chars;
log("${chars}"); // ["a","b"]
log("${jsonChars}"); // ["a","b"]

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

Future support for converting to structs and other types: [#2188](https://github.com/winglang/wing/issues/2118)
## Safely convert to structs
```js playground
struct Foo {
val1: str;
val2: num;
}

let jFoo = {
val1: "cool",
val2: 21
};

let foo = Foo.fromJson(jFoo);
```

0 comments on commit 28391e8

Please sign in to comment.