Skip to content

kurojs/vanish

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vanish


Logo

Vanish is an Golang package to remove JSON fields without struct


Table of Contents

About The Project

Vanish is what you need when wanting remove some unwanted fields in JSON strings with Golang.

Here's why:

  • No need of define a struct to marshal/unmarshal JSON and remove theme. For example: To remove metadata field, we need to define an struct and do Unmarshal/Marshal in Go like
struct Person {
    Name string `json:"name,omitempty"`
}

person := Person{}
err := json.Unmarshal([]byte(`
    {
        "name": "Here my name",
        "metadata" : {
            "nested_string": "abc"
        },
    }
`), &person)
if err != nil {
    // handle error
}

wantedJSON, err := json.Marshal(&person)
...
  • You don't know exactly what type of the field is holding
  • You tell me

An this is not the silver bullet for your problem, use with carefull.

Getting Started

Getting it via Go get

go get github.com/kurojs/vanish

Usage

To using vanish, just import it an define a list of fields need to be removed

jsonData := `
    {
        "name": "Here my name",
        "metadata" : {
            "nested_string": "abc"
        },
        "number": 100
    }
`
tobeRemoved := []string{"metadata.nested_string", "number"}

wantedJSON, err := vanish.RemoveFields([]byte(jsonData), tobeRemoved)
if err != nil {
    // Handle error
}

fmt.Println(string(wantedJSON))

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

kuro (Chi Pham) - via Email

Project Link: https://github.com/kurojs/vanish

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages