Reshape JSON or XML with a JMESPath expression (JMESPath Community, a superset of the spec): extract fields, filter, sort, flatten and merge lists, build new objects. On top of the spec functions it adds grouping, string splitting, variables and arithmetic: group_by(@, &site) returns {site: [records]} (values(...) for the groups as a list; the key must be a string, so wrap numbers with to_string); split(name, '-')[0] splits a string; ([].let $d = name in interfaces[].{device: $d, port: name})[] binds a variable, here to reach the parent record; also zip, items, from_items, find_first, pad_left, upper, lower, trim, replace, $ (the root), + - * / % //. Example, group records by pair and reshape each group: values(group_by(@, &to_string(pair)))[*].{pair: [0].pair, primary: [?role=='primary'] | [0].name}. Quote keys containing a dash ("foo-bar"): unquoted, foo-bar is a subtraction. Literals need backticks or quotes: [?priority > `2`], [?status=='open'] (a bare word is a field name). Pass previous results as data (e.g. {"tickets": results.a, "users": results.b}); a string in data is parsed as JSON (or XML). For large inputs, pass a JSON or XML file from the workspace object storage as s3_file instead; it is still parsed whole in worker memory. input_format xml parses XML first (xmltodict): attributes become "@name" keys and namespaced tags "ns:tag" keys (quote both in expressions), values are strings or null for an empty element (compare and sort numbers with to_number, as strings sort lexically), and an element that appears once is an object (wrap with to_array). With the default expression @ the step just converts XML to JSON. write_to_s3 stores the result as JSON in object storage and returns its S3 object, which a later step takes as s3_file. Syntax errors repeat the expression with a caret under the failing column. Validated live on Windmill with MinIO object storage (JSON and XML flow steps, merging, S3 round trip, error cases).
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 | |