forked from ehmicky/Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjmespath.format.txt
More file actions
195 lines (138 loc) · 8.8 KB
/
jmespath.format.txt
File metadata and controls
195 lines (138 loc) · 8.8 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
┏━━━━━━━━━━━━━━┓
┃ JMESPATH ┃
┗━━━━━━━━━━━━━━┛
VERSION ==> #2024-10-05
┌───────────┐
│ CHAIN │
└───────────┘
JSON ==> #Values are JSON only
EXPR #Everything thing in this doc is an EXPR
#I.e. chainable
null #Result if either:
# - no value (undefined)
# - out-of-bound
# - EXPR has wrong type, e.g. OBJ_EXPR[NUM]
# - using an EXPR|operator on undefined|null value
#I.e. on problem EXPR usually just returns null
#However, it throws an error on:
# - syntax error
# - invalid type to FUNC() ARG
# - ARR_EXPR[...:...:0]
@ #Current OBJ
#At the chain start, it is the root value passed as input
#In sub-EXPR or in FUNC ARG, it is the previous EXPR
#If an EXPR, sub-EXPR or FUNC ARG does not start with @, it is implied
# - VAR -> @.VAR
# - [0] -> @[0]
# - [?a == 1] -> @[?@.a == 1]
# - length(...) -> @.length(...)
PROJECTION ==> #When result of EXPR is an OBJ|ARR, subsequent EXPRs in the chain iterate over each member|item
#Including with .* and [*]
EXPR | EXPR2 #Like EXPR2, but with EXPR as @
#Similar to just chaining except:
# - if EXPR was iterating over multiple items (due to projection)
# - EXPR2 aggregates them as a single ARR as @
#E.g.:
# - *[0] + {a: [1, 2], b: [3, 4]} -> [1, 3]
# - * | [0] + {a: 1, b: 2} -> 1
┌─────────┐
│ RAW │
└─────────┘
'...' #STR, as is
#' must be \-escaped
#No backslash sequence
#No C0 control chars
`...` #Any JSON value
#` must be escaped as \u0060
#Must be used to pass a literal non-STR JSON value as is
# - including for FUNC() ARGs
# - except for NUM in ARR_EXPR[NUM[:...]]
┌────────────┐
│ OBJECT │
└────────────┘
OBJ_EXPR.VAR #OBJ.VAR
#VAR:
# - if no [:alnum:]_, must "-quote
# - if "-quoted, can use JSON backslash sequence like \" \\ \n or \uUUUU
OBJ_EXPR.* #All OBJ members
┌───────────┐
│ ARRAY │
└───────────┘
ARR_EXPR[NUM] #NUM is 0-based, can be negative (from end)
ARR_EXPR[*] #All ARR items
ARR_EXPR[] #Same but flattens sub-ARRs (only one depth level)
ARR_EXPR[[NUM]:[NUM2][:[NUM3]]] #Sliced ARR
#NUM|NUM2: def start|end, negative NUM is from end
#NUM3 is step: def 1, negative NUM reverses
┌─────────────┐
│ BOOLEAN │
└─────────────┘
EXPR || && EXPR #Either BOOL logic, or chaining
!EXPR #EXPR is transtyped to BOOL:
# - null and empty STR|OBJ|ARR: false
# - NUM: always true
(EXPR) #Parenthesis for operator priority
┌───────────────┐
│ TRANSFORM │
└───────────────┘
EXPR.[EXPR,...] #ARR with items EXPR
EXPR.{VAR: EXPR,...} #OBJ with keys VAR and values EXPR
ARR_EXPR[?EXPR OP EXPR] #ARR, filtered
#OP is:
# - == != for any type (deep comparison, unordered)
# - < <= >= > for NUM only
┌───────────────────┐
│ FUNCTION MAIN │
└───────────────────┘
FUNC(ARG_EXPR,...) #Syntax for all the FUNCs below
#ARG's type is FUNC-specific
EXPR.FUNC(ARG_EXPR,...) #Same but @ is EXPR
&EXPR #Type of some FUNC ARG
#Lazily evaluated, similar to a JavaScript FUNC
┌──────────────────┐
│ FUNCTION ANY │
└──────────────────┘
type(VAL)->STR #Returns 'null|string|boolean|number|array|object'
not_null(VAL,...)->VAL #First VAL not null. If none, returns null
┌─────────────────────┐
│ FUNCTION NUMBER │
└─────────────────────┘
to_number(VAL)->NUM #If VAL is not NUM or 'NUM', returns null
abs(NUM)->NUM #
ceil(NUM)->NUM #
floor(NUM)->NUM #
avg(NUM_ARR)->NUM #
sum(NUM_ARR)->NUM #
min|max(NUM_ARR)->NUM #
min_by|max_by(NUM_ARR, &EXPR)->NUM#
sort(NUM_ARR)->NUM_ARR #
sort_by(NUM_ARR, &EXPR)->NUM_ARR #
┌─────────────────────┐
│ FUNCTION STRING │
└─────────────────────┘
to_string(VAL)->STR #If VAL is not STR, returns JSON.stringify(VAL)
length(STR)->NUM #In principle, in codepoints, but some implementations seem to use UTF-16 code units
contains(STR, STR)->BOOL #
starts_with(STR, STR)->BOOL #
ends_with(STR, STR)->BOOL #
join(STR, STR_ARR)->STR #
reverse(STR)->STR #
min|max(STR_ARR)->STR #
min|max_by(STR_ARR, &EXPR)->STR #
sort(STR_ARR)->STR_ARR #
sort_by(STR_ARR, &EXPR)->STR_ARR #
┌─────────────────────┐
│ FUNCTION OBJECT │
└─────────────────────┘
length(OBJ)->NUM #
keys(OBJ)->STR_ARR #Unordered
values(OBJ)->ARR #Unordered
merge(OBJ,...)->OBJ #Shallow merge
┌────────────────────┐
│ FUNCTION ARRAY │
└────────────────────┘
to_array(VAL)->ARR #If VAL is not ARR, returns [VAL]
length(ARR)->NUM #
contains(ARR, VAL)->BOOL #
reverse(ARR)->ARR #
map(&EXPR, ARR)->ARR #