@@ -51,67 +51,263 @@ import {
51
51
* example.org#%#//scriptlet('json-prune', 'example')
52
52
* ```
53
53
*
54
- * For instance, the following call will return `{ one: 1}`
54
+ * JSON.parse call:
55
55
*
56
56
* ```html
57
57
* JSON.parse('{"one":1,"example":true}')
58
58
* ```
59
59
*
60
+ * Input JSON:
61
+ *
62
+ * ```json
63
+ * {
64
+ * "one": 1,
65
+ * "example": true
66
+ * }
67
+ * ```
68
+ *
69
+ * Output:
70
+ *
71
+ * ```json
72
+ * {
73
+ * "one": 1
74
+ * }
75
+ * ```
76
+ *
60
77
* 1. If there are no specified properties in the result of JSON.parse call, pruning will NOT occur
61
78
*
62
79
* ```adblock
63
80
* example.org#%#//scriptlet('json-prune', 'one', 'obligatoryProp')
64
81
* ```
65
82
*
66
- * For instance, the following call will return `{ one: 1, two: 2}`
83
+ * JSON.parse call:
67
84
*
68
85
* ```html
69
86
* JSON.parse('{"one":1,"two":2}')
70
87
* ```
71
88
*
89
+ * Input JSON:
90
+ *
91
+ * ```json
92
+ * {
93
+ * "one": 1,
94
+ * "two": 2
95
+ * }
96
+ * ```
97
+ *
98
+ * Output:
99
+ *
100
+ * ```json
101
+ * {
102
+ * "one": 1,
103
+ * "two": 2
104
+ * }
105
+ * ```
106
+ *
72
107
* 1. A property in a list of properties can be a chain of properties
73
108
*
74
109
* ```adblock
75
110
* example.org#%#//scriptlet('json-prune', 'a.b', 'ads.url.first')
76
111
* ```
77
112
*
113
+ * JSON.parse call:
114
+ *
115
+ * ```html
116
+ * JSON.parse('{"a":{"b":123},"ads":{"url":{"first":"abc"}}}')
117
+ * ```
118
+ *
119
+ * Input JSON:
120
+ *
121
+ * ```json
122
+ * {
123
+ * "a": {
124
+ * "b": 123
125
+ * },
126
+ * "ads": {
127
+ * "url": {
128
+ * "first": "abc"
129
+ * }
130
+ * }
131
+ * }
132
+ * ```
133
+ *
134
+ * Output:
135
+ *
136
+ * ```json
137
+ * {
138
+ * "a": {},
139
+ * "ads": {
140
+ * "url": {
141
+ * "first": "abc"
142
+ * }
143
+ * }
144
+ * }
145
+ * ```
146
+ *
78
147
* 1. Removes property `content.ad` from the results of JSON.parse call if its error stack trace contains `test.js`
79
148
*
80
149
* ```adblock
81
150
* example.org#%#//scriptlet('json-prune', 'content.ad', '', 'test.js')
82
151
* ```
83
152
*
153
+ * JSON.parse call:
154
+ *
155
+ * ```html
156
+ * JSON.parse('{"content":{"ad":{"src":"a.js"}}}')
157
+ * ```
158
+ *
159
+ * Input JSON:
160
+ *
161
+ * ```json
162
+ * {
163
+ * "content": {
164
+ * "ad": {
165
+ * "src": "a.js"
166
+ * }
167
+ * }
168
+ * }
169
+ * ```
170
+ *
171
+ * Output:
172
+ *
173
+ * ```json
174
+ * {
175
+ * "content": {}
176
+ * }
177
+ * ```
178
+ *
84
179
* 1. A property in a list of properties can be a chain of properties with wildcard in it
85
180
*
86
181
* ```adblock
87
182
* example.org#%#//scriptlet('json-prune', 'content.*.media.src', 'content.*.media.ad')
88
183
* ```
89
184
*
185
+ * JSON.parse call:
186
+ *
187
+ * ```html
188
+ * JSON.parse('{"content":{"block1":{"media":{"src":"1.jpg","ad":true}},"block2":{"media":{"src":"2.jpg"}} }}')
189
+ * ```
190
+ *
191
+ * Input JSON:
192
+ *
193
+ * ```json
194
+ * {
195
+ * "content": {
196
+ * "block1": {
197
+ * "media": {
198
+ * "src": "1.jpg",
199
+ * "ad": true
200
+ * }
201
+ * },
202
+ * "block2": {
203
+ * "media": {
204
+ * "src": "2.jpg"
205
+ * }
206
+ * }
207
+ * }
208
+ * }
209
+ * ```
210
+ *
211
+ * Output:
212
+ *
213
+ * ```json
214
+ * {
215
+ * "content": {
216
+ * "block1": {
217
+ * "media": {
218
+ * "ad": true
219
+ * }
220
+ * },
221
+ * "block2": {
222
+ * "media": {}
223
+ * }
224
+ * }
225
+ * }
226
+ * ```
227
+ *
90
228
* 1. Removes every property from `videos` object if it has `isAd` key
91
229
*
92
230
* ```adblock
93
231
* example.org#%#//scriptlet('json-prune', 'videos.{-}.isAd')
94
232
* ```
95
233
*
96
- * For instance, the following call will return `{ videos: { video2: { src: 'video1.mp4' } } }`
234
+ * JSON.parse call:
97
235
*
98
236
* ```html
99
237
* JSON.parse('{"videos":{"video1":{"isAd":true,"src":"video1.mp4"},"video2":{"src":"video1.mp4"}}}')
100
238
* ```
101
239
*
240
+ * Input JSON:
241
+ *
242
+ * ```json
243
+ * {
244
+ * "videos": {
245
+ * "video1": {
246
+ * "isAd": true,
247
+ * "src": "video1.mp4"
248
+ * },
249
+ * "video2": {
250
+ * "src": "video1.mp4"
251
+ * }
252
+ * }
253
+ * }
254
+ * ```
255
+ *
256
+ * Output:
257
+ *
258
+ * ```json
259
+ * {
260
+ * "videos": {
261
+ * "video2": {
262
+ * "src": "video1.mp4"
263
+ * }
264
+ * }
265
+ * }
266
+ * ```
267
+ *
102
268
* 1. Removes every property from `videos` object if it has `isAd` key with `true` value
103
269
*
104
270
* ```adblock
105
271
* example.org#%#//scriptlet('json-prune', 'videos.{-}.isAd.[=].true')
106
272
* ```
107
273
*
108
- * For instance, the following call will return `{ videos: { video2: { isAd: false, src: 'video1.mp4' } } }`
274
+ * JSON.parse call:
109
275
*
110
276
* ```html
111
277
* JSON.parse('{"videos":{"video1":{"isAd":true,"src":"video1.mp4"},"video2":{"isAd":false,"src":"video1.mp4"}}}')
112
278
* ```
113
279
*
114
- * 1. Call with no arguments will log the current hostname and json payload at the console
280
+ * Input JSON:
281
+ *
282
+ * ```json
283
+ * {
284
+ * "videos": {
285
+ * "video1": {
286
+ * "isAd": true,
287
+ * "src": "video1.mp4"
288
+ * },
289
+ * "video2": {
290
+ * "isAd": false,
291
+ * "src": "video1.mp4"
292
+ * }
293
+ * }
294
+ * }
295
+ * ```
296
+ *
297
+ * Output:
298
+ *
299
+ * ```json
300
+ * {
301
+ * "videos": {
302
+ * "video2": {
303
+ * "isAd": false,
304
+ * "src": "video1.mp4"
305
+ * }
306
+ * }
307
+ * }
308
+ * ```
309
+ *
310
+ * 1. Call with no arguments will log the current hostname and JSON payload at the console
115
311
*
116
312
* ```adblock
117
313
* example.org#%#//scriptlet('json-prune')
0 commit comments