minio / simdjson-go

Golang port of simdjson: parsing gigabytes of JSON per second
Apache License 2.0
1.8k stars 85 forks source link

Add Object&Array Element Deletion #72

Closed klauspost closed 1 year ago

klauspost commented 2 years ago

Also upgrade CI and dependencies

It is possible to delete one or more elements in an object.

(*Object).DeleteElems(fn, onlyKeys) will call back fn for each key+ value.

If true is returned, the key+value is deleted. A key filter can be provided for optional filtering. If the callback function is nil all elements matching the filter will be deleted. If both are nil all elements are deleted.

Example:

    // The object we are modifying
    var obj *simdjson.Object

    // Delete all entries where the key is "unwanted":
    err = obj.DeleteElems(func(key []byte, i Iter) bool {
        return string(key) == "unwanted")
    }, nil)

    // Alternative version with prefiltered keys:
    err = obj.DeleteElems(nil, map[string]struct{}{"unwanted": {}})

(*Array).DeleteElems(fn func(i Iter) bool) will call back fn for each array value. If the function returns true the element is deleted in the array.

    // The array we are modifying
    var array *simdjson.Array

    // Delete all entries that are strings.
    array.DeleteElems(func(i Iter) bool {
        return i.Type() == TypeString
    })