Skip to content

Commit 7cef327

Browse files
committed
docs: update examples to use struct-based Operation syntax
Replace quoted field names with struct field syntax in all documentation examples. Updated README.md, docs/json-patch.md, and docs/json-predicate.md to consistently use Op, Path, Str fields instead of "op", "path", "str" quoted keys.
1 parent 3dd8d2f commit 7cef327

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -321,19 +321,19 @@ fmt.Printf("Version: %d, Status: %s, Enabled: %t\n",
321321
patch := []jsonpatch.Operation{
322322
// Test current value before modifying
323323
{
324-
"op": "test",
325-
"path": "/version",
324+
Op: "test",
325+
Path: "/version",
326326
Value: 1,
327327
},
328328
// Make the change
329329
{
330-
"op": "replace",
331-
"path": "/status",
330+
Op: "replace",
331+
Path: "/status",
332332
Value: "updated",
333333
},
334334
// Increment version
335335
{
336-
"op": "inc",
336+
Op: "inc",
337337
Path: "/version",
338338
Inc: 1,
339339
},
@@ -360,8 +360,8 @@ var patch []jsonpatch.Operation
360360
// Update multiple items efficiently
361361
for i := 0; i < itemCount; i++ {
362362
patch = append(patch, jsonpatch.Operation{
363-
"op": "replace",
364-
"path": fmt.Sprintf("/items/%d/status", i),
363+
Op: "replace",
364+
Path: fmt.Sprintf("/items/%d/status", i),
365365
Value: "processed",
366366
})
367367
}
@@ -375,19 +375,19 @@ result, err := jsonpatch.ApplyPatch(doc, patch)
375375
patch := []jsonpatch.Operation{
376376
// Add to end of array
377377
{
378-
"op": "add",
378+
Op: "add",
379379
Path: "/users/-",
380380
Value: map[string]interface{}{"name": "New User"},
381381
},
382382
// Insert at specific position
383383
{
384-
"op": "add",
384+
Op: "add",
385385
Path: "/tags/0",
386386
Value: "important",
387387
},
388388
// Remove array element
389389
{
390-
"op": "remove",
390+
Op: "remove",
391391
Path: "/items/2",
392392
},
393393
}
@@ -401,17 +401,17 @@ result, err := jsonpatch.ApplyPatch(doc, patch)
401401
patch := []jsonpatch.Operation{
402402
// Insert text at position
403403
{
404-
"op": "str_ins",
404+
Op: "str_ins",
405405
Path: "/content",
406406
Pos: 0,
407-
"str": "Prefix: ",
407+
Str: "Prefix: ",
408408
},
409409
// Insert at end
410410
{
411-
"op": "str_ins",
411+
Op: "str_ins",
412412
Path: "/content",
413413
Pos: 20,
414-
"str": " (Updated)",
414+
Str: " (Updated)",
415415
},
416416
}
417417

docs/json-patch.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ var patch []jsonpatch.Operation
133133
// Update multiple fields
134134
for i := 0; i < 3; i++ {
135135
patch = append(patch, jsonpatch.Operation{
136-
"op": "replace",
137-
"path": fmt.Sprintf("/items/%d/status", i),
136+
Op: "replace",
137+
Path: fmt.Sprintf("/items/%d/status", i),
138138
Value: "processed",
139139
})
140140
}

docs/json-predicate.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ All conditions must be true.
165165

166166
```go
167167
{
168-
"op": "and",
168+
Op: "and",
169169
Apply: [
170170
{Op: "defined", Path: "/user/email"},
171171
{Op: "type", Path: "/user/age", Value: "number"},
@@ -180,7 +180,7 @@ At least one condition must be true.
180180

181181
```go
182182
{
183-
"op": "or",
183+
Op: "or",
184184
Apply: [
185185
{Op: "contains", Path: "/tags", Value: "admin"},
186186
{Op: "contains", Path: "/tags", Value: "moderator"}
@@ -194,7 +194,7 @@ Invert a condition.
194194

195195
```go
196196
{
197-
"op": "not",
197+
Op: "not",
198198
Apply: [
199199
{Op: "contains", Path: "/tags", Value: "banned"}
200200
]
@@ -208,7 +208,7 @@ Invert a condition.
208208
```go
209209
patch := []jsonpatch.Operation{
210210
{
211-
"op": "and",
211+
Op: "and",
212212
Apply: []jsonpatch.Operation{
213213
{Op: "defined", Path: "/user/name"},
214214
{Op: "defined", Path: "/user/email"},
@@ -225,11 +225,11 @@ patch := []jsonpatch.Operation{
225225
```go
226226
patch := []jsonpatch.Operation{
227227
{
228-
"op": "or",
228+
Op: "or",
229229
Apply: []jsonpatch.Operation{
230230
{Op: "contains", Path: "/roles", Value: "admin"},
231231
{
232-
"op": "and",
232+
Op: "and",
233233
Apply: []jsonpatch.Operation{
234234
{Op: "contains", Path: "/roles", Value: "user"},
235235
{Op: "contains", Path: "/permissions", Value: "write"},
@@ -247,7 +247,7 @@ patch := []jsonpatch.Operation{
247247
{Op: "defined", Path: "/required_field"},
248248
{Op: "type", Path: "/required_field", Value: "string"},
249249
{
250-
"op": "not",
250+
Op: "not",
251251
Apply: []jsonpatch.Operation{
252252
{Op: "test", Path: "/required_field", Value: ""},
253253
},

0 commit comments

Comments
 (0)