-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dpdlDecodeJSON.h
48 lines (36 loc) · 1 KB
/
dpdlDecodeJSON.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File: json/dpdlDecodeJSON.h
#
# Example: Sample Dpdl script that decodes a json file into a struct
#
# Author: A.Costa
# e-mail: ac@dpdl.io
#
#
import('io')
import('json')
struct myJsonData {
string mystr
int i_num
float f_num
double d_num
bool b_val
}
# main
println("decoding json to struct....")
string json_file = "./Test/test2.json"
println("reading json from file: " + json_file)
string content = io.readStr(json_file)
raise(content, "Error in reading json file")
struct myJsonData data
data = json.decode(content, data)
raise(data, "Error in decoding json")
println("data.mystr: " + data.mystr)
println("data.i_num: " + data.i_num)
println("data.f_num: " + data.f_num)
println("data.d_num: " + data.d_num)
println("data.b_val: " + data.b_val)
println("type of mystr is: " + typeof(data.mystr))
println("type of i_num is: " + typeof(data.i_num))
println("type of f_num is: " + typeof(data.f_num))
println("type of d_num is: " + typeof(data.d_num))
println("type of b_val is: " + typeof(data.b_val))