https://github.com/petems/remove-singleton-arrays
A Golang library to remove singleton arrays
https://github.com/petems/remove-singleton-arrays
Last synced: 17 days ago
JSON representation
A Golang library to remove singleton arrays
- Host: GitHub
- URL: https://github.com/petems/remove-singleton-arrays
- Owner: petems
- Created: 2019-03-19T11:23:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-22T15:56:11.000Z (over 6 years ago)
- Last Synced: 2025-06-15T02:03:09.925Z (17 days ago)
- Language: Go
- Size: 51.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# remove-singleton-arrays
[](https://travis-ci.org/petems/remove-singleton-arrays)
This is a golang package to remove arrays that only have one element from a JSON object.
Arrays with more than one element are ignored.
## Usage
To remove all singleton arrays:
```go
import (
. "github.com/petems/remove-singleton-arrays"
)RemoveSingletonArrays(`{"a":1,"b":["2"]}`) // returns `{"a":1,"b":"2"}`
RemoveSingletonArrays(`{"a":1,"b":["2, 3"]}`) // returns `{"a":1,"b":["2","3"]}`
```To remove singleton arrays with selected exceptions:
```go
import (
"github.com/petems/remove-singleton-arrays"
)removesingletonarrays.WithIgnores(`{"a":1,"b":["2"]}`, []string{"b"}) // returns `{"a":1,"b":["2"]}`
removesingletonarrays.WithIgnores(`{"a":1,"b":["2"]}`, []string{"a"}) // returns `{"a":1,"b":"2"}`
```