forked from culturekings/shopify-json-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_decode.liquid
395 lines (382 loc) · 24.2 KB
/
json_decode.liquid
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
{% assign jd__start_type = '0' %}
{% assign jd__object_type = '1' %}
{% assign jd__array_type = '2' %}
{% assign jd__string_type = '3' %}
{% assign jd__number_type = '4' %}
{% assign jd__true_type = '5' %}
{% assign jd__false_type = '6' %}
{% assign jd__null_type = '7' %}
{% assign jd__current_token = '' %}
{% assign jd__current_namespace = jd__namespace %}
{% assign jd__current_type = jd__start_type %}
{% assign jd__local_keys = '' %}
{% assign jd__local_values = '' %}
{% assign jd__level_keys = ' ' | split: '' %}
{% assign jd__level_values = ' ' | split: '' %}
{% assign jd__level_keys_array = '' | split: '' %}
{% assign jd__level_values_array = '' | split: '' %}
{% assign jd__stream = jd__data | split: '' %}
{% assign jd__error = false %}
{% assign jd__continue = false %}
{% assign jd__length_counter = 0 %}
{% assign jd__child_counter = 0 %}
{% assign jd__object_counter = 0 %}
{% assign jd__parent_type_array = '' | split: '' %}
{% assign jd__child_counter_array = '0' | split: ',' %}
{% assign jd__quote = '"' %}
{% assign jd__separator = '|jd__sp1|' %}
{% assign jd__separator_2 = '|jd__sp2|' %}
{% assign jd__valid_start_char_string = '[,{,",0,1,2,3,4,5,6,7,8,9,-,f,t,n' %}
{% assign jd__valid_start_char = jd__valid_start_char_string | split: ',' %}
{% assign jd__valid_start_char_type_string = '2,1,3,4,4,4,4,4,4,4,4,4,4,4,6,5,7' %}
{% assign jd__valid_start_char_type = jd__valid_start_char_type_string | split: ',' %}
{% assign jd__valid_number_string = '0,1,2,3,4,5,6,7,8,9,-,.,e,E,+' %}
{% assign jd__valid_number = jd__valid_number_string | split: ',' %}
{% for jd__char in jd__stream %}
{% assign jd__stripped_char = jd__char | strip %}
{% if jd__stripped_char != '' or jd__current_type == jd__string_type %}
{% case jd__current_type %}
{% when jd__start_type %}
{% for jd__current_valid_start_char in jd__valid_start_char %}
{% if jd__stripped_char == jd__current_valid_start_char %}
{% assign jd__current_type = jd__valid_start_char_type[forloop.index0] %}
{% assign jd__continue = true %}
{% assign jd__length_counter = 0 %}
{% if jd__stripped_char == '{' or jd__stripped_char == '[' %}
{% include 'jd__function' with 'array_push|jd__child_counter_array|jd__child_counter' %}
{% assign jd__child_counter_array = jd__yield_1 %}
{% assign jd__level_keys = jd__level_keys | join: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_keys_array|jd__level_keys' %}
{% assign jd__level_keys_array = jd__yield_1 %}
{% assign jd__level_keys = ' ' | split: '' %}
{% assign jd__level_values = jd__level_values | join: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_values_array|jd__level_values' %}
{% assign jd__level_values_array = jd__yield_1 %}
{% assign jd__level_values = ' ' | split: '' %}
{% assign jd__child_counter = 0 %}
{% endif %}
{% if jd__valid_number contains jd__stripped_char %}
{% assign jd__current_token = jd__current_token | append: jd__stripped_char %}
{% endif %}
{% break %}
{% endif %}
{% endfor %}
{% if jd__continue == true %}
{% assign jd__continue = false %}
{% continue %}
{% endif %}
{% assign jd__error = true %}
Invalid Start Character!
{% break %}
{% when jd__object_type %}
{% if jd__child_counter == 0 and jd__object_counter == 0 %}
{% include 'jd__function' with 'array_push|jd__parent_type_array|jd__current_type' %}
{% assign jd__parent_type_array = jd__yield_1 %}
{% assign jd__child_counter = jd__child_counter | plus: 1 %}
{% endif %}
{% if jd__stripped_char == '}' %}
{% if jd__local_keys != '' %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__current_token %}
{% else %}
{% assign jd__local_keys = jd__local_keys | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__current_token %}
{% endif %}
{% include 'jd__function' with 'array_push|jd__level_keys|jd__current_namespace' %}
{% assign jd__level_keys = jd__yield_1 | join: jd__separator_2 | lstrip | remove_first: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_values|jd__current_token' %}
{% assign jd__level_values = jd__yield_1 | join: jd__separator_2 | lstrip | remove_first: jd__separator_2 %}
{% include 'jd__function' with 'array_pop|jd__parent_type_array' %}
{% assign jd__parent_type_array = jd__yield_2 %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% include 'jd__function' with 'array_pop|jd__current_namespace|.' %}
{% assign jd__current_namespace = jd__yield_2 %}
{% include 'jd__function' with 'array_pop|jd__child_counter_array' %}
{% assign jd__child_counter = jd__yield_1 %}
{% assign jd__child_counter_array = jd__yield_2 %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__keys' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_keys %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__values' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_values %}
{% include 'jd__function' with 'array_pop|jd__level_keys_array' %}
{% assign jd__level_keys = jd__yield_1 | split: jd__separator_2 %}
{% assign jd__level_keys_array = jd__yield_2 %}
{% include 'jd__function' with 'array_pop|jd__level_values_array' %}
{% assign jd__level_values = jd__yield_1 | split: jd__separator_2 %}
{% assign jd__level_values_array = jd__yield_2 %}
{% assign jd__current_token = "Object" %}
{% continue %}
{% endif %}
{% if jd__object_counter == 0 and jd__stripped_char == ',' %}
{% if jd__local_keys != '' %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__current_token %}
{% else %}
{% assign jd__local_keys = jd__local_keys | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__current_token %}
{% endif %}
{% include 'jd__function' with 'array_push|jd__level_keys|jd__current_namespace' %}
{% assign jd__level_keys = jd__yield_1 %}
{% include 'jd__function' with 'array_push|jd__level_values|jd__current_token' %}
{% assign jd__level_values = jd__yield_1 %}
{% include 'jd__function' with 'array_pop|jd__current_namespace|.' %}
{% assign jd__current_namespace = jd__yield_2 %}
{% assign jd__child_counter = jd__child_counter | plus: 1 %}
{% continue %}
{% endif %}
{% if jd__object_counter == 0 and jd__stripped_char == '"' %}
{% assign jd__object_counter = 1 %}
{% assign jd__current_type = jd__string_type %}
{% assign jd__current_token = '' %}
{% continue %}
{% endif %}
{% if jd__object_counter == 1 and jd__stripped_char == ':' %}
{% assign jd__object_counter = 2 %}
{% assign jd__current_namespace = jd__current_namespace | append:'.' | append: jd__current_token %}
{% assign jd__current_token = '' %}
{% continue %}
{% endif %}
{% if jd__object_counter == 2 %}
{% assign jd__object_counter = 0 %}
{% for jd__current_valid_start_char in jd__valid_start_char %}
{% if jd__stripped_char == jd__current_valid_start_char %}
{% assign jd__current_type = jd__valid_start_char_type[forloop.index0] %}
{% assign jd__continue = true %}
{% assign jd__length_counter = 0 %}
{% if jd__stripped_char == '{' or jd__stripped_char == '[' %}
{% include 'jd__function' with 'array_push|jd__child_counter_array|jd__child_counter' %}
{% assign jd__child_counter_array = jd__yield_1 %}
{% assign jd__child_counter = 0 %}
{% assign jd__level_keys = jd__level_keys | join: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_keys_array|jd__level_keys' %}
{% assign jd__level_keys_array = jd__yield_1 %}
{% assign jd__level_keys = ' ' | split: '' %}
{% assign jd__level_values = jd__level_values | join: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_values_array|jd__level_values' %}
{% assign jd__level_values_array = jd__yield_1 %}
{% assign jd__level_values = ' ' | split: '' %}
{% endif %}
{% if jd__valid_number contains jd__stripped_char %}
{% assign jd__current_token = jd__current_token | append: jd__stripped_char %}
{% endif %}
{% break %}
{% endif %}
{% endfor %}
{% if jd__continue == true %}
{% assign jd__continue = false %}
{% continue %}
{% endif %}
{% endif %}
{% assign jd__error = true %}
Invalid Character following Object Start!
{% break %}
{% when jd__array_type %}
{% if jd__child_counter == 0 %}
{% include 'jd__function' with 'array_push|jd__parent_type_array|jd__current_type' %}
{% assign jd__parent_type_array = jd__yield_1 %}
{% assign jd__current_namespace = jd__current_namespace | append:'.' | append: jd__child_counter %}
{% endif %}
{% if jd__stripped_char == "," %}
{% if jd__local_keys != '' %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__current_token %}
{% else %}
{% assign jd__local_keys = jd__local_keys | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__current_token %}
{% endif %}
{% include 'jd__function' with 'array_push|jd__level_keys|jd__current_namespace' %}
{% assign jd__level_keys = jd__yield_1 %}
{% include 'jd__function' with 'array_push|jd__level_values|jd__current_token' %}
{% assign jd__level_values = jd__yield_1 %}
{% include 'jd__function' with 'array_pop|jd__current_namespace|.' %}
{% assign jd__current_namespace = jd__yield_2 %}
{% assign jd__current_namespace = jd__current_namespace | append:'.' | append: jd__child_counter %}
{% continue %}
{% endif %}
{% if jd__stripped_char == "]" %}
{% if jd__child_counter != 0 %}
{% if jd__local_keys != '' %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__current_token %}
{% else %}
{% assign jd__local_keys = jd__local_keys | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__current_token %}
{% endif %}
{% endif %}
{% include 'jd__function' with 'array_push|jd__level_keys|jd__current_namespace' %}
{% assign jd__level_keys = jd__yield_1 | join: jd__separator_2 | lstrip | remove_first: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_values|jd__current_token' %}
{% assign jd__level_values = jd__yield_1 | join: jd__separator_2 | lstrip | remove_first: jd__separator_2 %}
{% include 'jd__function' with 'array_pop|jd__parent_type_array' %}
{% assign jd__parent_type_array = jd__yield_2 %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% include 'jd__function' with 'array_pop|jd__current_namespace|.' %}
{% assign jd__current_namespace = jd__yield_2 %}
{% include 'jd__function' with 'array_pop|jd__child_counter_array' %}
{% assign jd__child_counter = jd__yield_1 %}
{% assign jd__child_counter_array = jd__yield_2 %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__keys' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_keys %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__values' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_values %}
{% include 'jd__function' with 'array_pop|jd__level_keys_array' %}
{% assign jd__level_keys = jd__yield_1 | split: jd__separator_2 %}
{% assign jd__level_keys_array = jd__yield_2 %}
{% include 'jd__function' with 'array_pop|jd__level_values_array' %}
{% assign jd__level_values = jd__yield_1 | split: jd__separator_2 %}
{% assign jd__level_values_array = jd__yield_2 %}
{% assign jd__current_token = "Array" %}
{% continue %}
{% endif %}
{% if jd__stripped_char != ']' %}
{% for jd__current_valid_start_char in jd__valid_start_char %}
{% if jd__stripped_char == jd__current_valid_start_char %}
{% assign jd__child_counter = jd__child_counter | plus: 1 %}
{% assign jd__current_type = jd__valid_start_char_type[forloop.index0] %}
{% assign jd__continue = true %}
{% assign jd__current_token = '' %}
{% assign jd__length_counter = 0 %}
{% if jd__stripped_char == '{' or jd__stripped_char == '[' %}
{% include 'jd__function' with 'array_push|jd__child_counter_array|jd__child_counter' %}
{% assign jd__child_counter_array = jd__yield_1 %}
{% assign jd__child_counter = 0 %}
{% assign jd__level_keys = jd__level_keys | join: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_keys_array|jd__level_keys' %}
{% assign jd__level_keys_array = jd__yield_1 %}
{% assign jd__level_keys = ' ' | split: '' %}
{% assign jd__level_values = jd__level_values | join: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_values_array|jd__level_values' %}
{% assign jd__level_values_array = jd__yield_1 %}
{% assign jd__level_values = ' ' | split: '' %}
{% endif %}
{% if jd__valid_number contains jd__stripped_char %}
{% assign jd__current_token = jd__current_token | append: jd__stripped_char %}
{% endif %}
{% break %}
{% endif %}
{% endfor %}
{% endif %}
{% if jd__continue == true %}
{% assign jd__continue = false %}
{% continue %}
{% endif %}
Invalid Character following Array Start!
{% assign jd__error = true %}
{% break %}
{% when jd__string_type %}
{% if jd__stripped_char_2 != "\" and jd__stripped_char == jd__quote %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% continue %}
{% endif %}
{% if jd__stripped_char_3 == "\" and jd__stripped_char_2 == "\" and jd__stripped_char == jd__quote %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% continue %}
{% endif %}
{% assign jd__current_token = jd__current_token | append: jd__char %}
{% when jd__number_type %}
{% unless jd__valid_number contains jd__stripped_char %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% if jd__object_counter == 0 and jd__stripped_char == '}' %}
{% if jd__local_keys != '' %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__current_token %}
{% else %}
{% assign jd__local_keys = jd__local_keys | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__current_token %}
{% endif %}
{% include 'jd__function' with 'array_push|jd__level_keys|jd__current_namespace' %}
{% assign jd__level_keys = jd__yield_1 | join: jd__separator_2 | lstrip | remove_first: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_values|jd__current_token' %}
{% assign jd__level_values = jd__yield_1 | join: jd__separator_2 | lstrip | remove_first: jd__separator_2 %}
{% include 'jd__function' with 'array_pop|jd__parent_type_array' %}
{% assign jd__parent_type_array = jd__yield_2 %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% include 'jd__function' with 'array_pop|jd__current_namespace|.' %}
{% assign jd__current_namespace = jd__yield_2 %}
{% include 'jd__function' with 'array_pop|jd__child_counter_array' %}
{% assign jd__child_counter = jd__yield_1 %}
{% assign jd__child_counter_array = jd__yield_2 %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__keys' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_keys %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__values' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_values %}
{% include 'jd__function' with 'array_pop|jd__level_keys_array' %}
{% assign jd__level_keys = jd__yield_1 | split: jd__separator_2 %}
{% assign jd__level_keys_array = jd__yield_2 %}
{% include 'jd__function' with 'array_pop|jd__level_values_array' %}
{% assign jd__level_values = jd__yield_1 | split: jd__separator_2 %}
{% assign jd__level_values_array = jd__yield_2 %}
{% assign jd__current_token = "Object" %}
{% continue %}
{% endif %}
{% if jd__object_counter == 0 and jd__stripped_char == ',' %}
{% if jd__local_keys != '' %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__current_token %}
{% else %}
{% assign jd__local_keys = jd__local_keys | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__current_token %}
{% endif %}
{% include 'jd__function' with 'array_push|jd__level_keys|jd__current_namespace' %}
{% assign jd__level_keys = jd__yield_1 %}
{% include 'jd__function' with 'array_push|jd__level_values|jd__current_token' %}
{% assign jd__level_values = jd__yield_1 %}
{% include 'jd__function' with 'array_pop|jd__current_namespace|.' %}
{% assign jd__current_namespace = jd__yield_2 %}
{% assign jd__child_counter = jd__child_counter | plus: 1 %}
{% continue %}
{% endif %}
{% continue %}
{% endunless %}
{% assign jd__current_token = jd__current_token | append: jd__stripped_char %}
{% when jd__true_type %}
{% assign jd__length_counter = jd__length_counter | plus: 1 %}
{% if jd__length_counter == 3 %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% assign jd__current_token = "true" %}
{% continue %}
{% endif %}
{% when jd__false_type %}
{% assign jd__length_counter = jd__length_counter | plus: 1 %}
{% if jd__length_counter == 4 %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% assign jd__current_token = "false" %}
{% continue %}
{% endif %}
{% when jd__null_type %}
{% assign jd__length_counter = jd__length_counter | plus: 1 %}
{% if jd__length_counter == 3 %}
{% assign jd__current_type = jd__parent_type_array.last %}
{% assign jd__current_token = "null" %}
{% continue %}
{% endif %}
{% else %}
Ended up in an unsupported type!
{% assign jd__error = true %}
{% break %}
{% endcase %}
{% assign jd__stripped_char_4 = jd__stripped_char_3 %}
{% assign jd__stripped_char_3 = jd__stripped_char_2 %}
{% assign jd__stripped_char_2 = jd__stripped_char %}
{% continue %}
{% endif %}
{% endfor %}
{% if jd__local_keys != '' %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__current_token %}
{% else %}
{% assign jd__local_keys = jd__local_keys | append: jd__current_namespace %}
{% assign jd__local_values = jd__local_values | append: jd__current_token %}
{% endif %}
{% include 'jd__function' with 'array_push|jd__level_keys|jd__current_namespace' %}
{% assign jd__level_keys = jd__yield_1 | join: jd__separator_2 %}
{% include 'jd__function' with 'array_push|jd__level_values|jd__current_token' %}
{% assign jd__level_values = jd__yield_1 | join: jd__separator_2 %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__keys' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_keys %}
{% assign jd__local_keys = jd__local_keys | append: jd__separator | append: jd__current_namespace | append: '__values' %}
{% assign jd__local_values = jd__local_values | append: jd__separator | append: jd__level_values %}
{% if jd__error == false %}
{% assign jd__global_keys = jd__global_keys | join: jd__separator | append: jd__local_keys | split: jd__separator %}
{% assign jd__global_values = jd__global_values | join: jd__separator | append: jd__local_values | split: jd__separator %}
{% endif %}