-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjson_expression_notation.txt
101 lines (75 loc) · 2.98 KB
/
json_expression_notation.txt
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Last week I wrote a new language required for automating some tasks for my job. It's a programming language for picking up values from JSON docs, and works as follows:
Given the following json:
[
{ "properties" : [{ "name" : "color", "type" : "string"}, { "name" : "age", "type" : "int"} ]
, "selection" : {"index" : 1 , "active" : true }
, "people" :
[{ "name" : "David"
, "property" :
{ "color" : "red", "age" : 25 }
},
{ "name" : "Charles"
, "property" :
{ "color" : "green", "age" : 32 }
},
{ "name" : "Charles"
, "property" :
{ "color" : "blue", "age" : 95 }
},
],
},
]
An expression in this language (which I've called JSON expression notation), resolves as follows:
Expression:
{people[2].name}'s {properties[selection.index].name}: {people[2].property.{properties[selection.index].name}}
Resolution:
---------------- Step 1:
{[{ "name" : "David"
, "property" :
{ "color" : "red", "age" : 25 }
},
{ "name" : "Charles"
, "property" :
{ "color" : "green", "age" : 32 }
},
{ "name" : "Charles"
, "property" :
{ "color" : "blue", "age" : 95 }
},
][2].name}'s {[{ "name" : "color", "type" : "string"}, { "name" : "age", "type" : "int"} ][selection.index].name}: {[{ "name" : "David"
, "property" :
{ "color" : "red", "age" : 25 }
},
{ "name" : "Charles"
, "property" :
{ "color" : "green", "age" : 32 }
},
{ "name" : "Charles"
, "property" :
{ "color" : "blue", "age" : 95 }
},
][2].property.{properties[selection.index].name}}
---------------- Step 2:
{{ "name" : "Charles"
, "property" :
{ "color" : "blue", "age" : 95 }
}.name}'s {[{ "name" : "color", "type" : "string"}, { "name" : "age", "type" : "int"} ][1].name}: {{ "name" : "Charles"
, "property" :
{ "color" : "blue", "age" : 95 }
}.property.{properties[selection.index].name}}
---------------- Step 3:
{"Charles"}'s {{ "name" : "age", "type" : "int"}.name}: {{ "color" : "blue", "age" : 95 }.{properties[selection.index].name}}
---------------- Step 4:
Charles's {"age"}: {{ "color" : "blue", "age" : 95 }.{[{ "name" : "color", "type" : "string"}, { "name" : "age", "type" : "int"} ][selection.index].name}}
---------------- Step 5:
Charles's age: {{ "color" : "blue", "age" : 95 }.{[{ "name" : "color", "type" : "string"}, { "name" : "age", "type" : "int"} ][1].name}}
---------------- Step 6:
Charles's age: {{ "color" : "blue", "age" : 95 }.{{ "name" : "age", "type" : "int"}.name}}
---------------- Step 7:
Charles's age: {{ "color" : "blue", "age" : 95 }.{"age"}}
---------------- Step 8:
Charles's age: {{ "color" : "blue", "age" : 95 }.age}
---------------- Step 9:
Charles's age: {95}
---------------- Step 10:
Charles's age: 95