-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import json | ||
|
||
struct Json3 { | ||
embed f64 | ||
} | ||
|
||
struct Json2 { | ||
Json3 | ||
inner []f64 | ||
} | ||
|
||
struct Json { | ||
Json2 | ||
test f64 | ||
} | ||
|
||
fn test_main() { | ||
str := '{"inner": [1, 2, 3, 4, 5],"test": 1.0, "embed": 2.0}' | ||
data := json.decode(Json, str) or { | ||
eprintln('Failed to decode json, error: ${err}') | ||
return | ||
} | ||
println(data) | ||
assert data.inner.len == 5 | ||
assert data.inner[0] == 1.0 | ||
assert data.inner[4] == 5.0 | ||
assert data.test == 1.0 | ||
assert data.embed == 2.0 | ||
|
||
assert dump(json.encode(data)) == '{"embed":2,"inner":[1,2,3,4,5],"test":1}' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters