Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ramizpolic/multiparser
Parse raw data into concrete types unburdened by serialization standards
https://github.com/ramizpolic/multiparser
deserialize golang parse unmarshal
Last synced: about 6 hours ago
JSON representation
Parse raw data into concrete types unburdened by serialization standards
- Host: GitHub
- URL: https://github.com/ramizpolic/multiparser
- Owner: ramizpolic
- License: apache-2.0
- Created: 2023-08-08T14:54:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-04T23:12:24.000Z (9 months ago)
- Last Synced: 2024-08-10T09:42:43.711Z (3 months ago)
- Topics: deserialize, golang, parse, unmarshal
- Language: Go
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# multiparser
Parse raw data into concrete types unburdened by serialization standards.### Example usage
Current multiparser example uses JSON and YAML parsers.
```go
package mainimport (
"github.com/ramizpolic/multiparser"
"github.com/ramizpolic/multiparser/parser"
)type object struct {
Data string `json:"data" yaml:"data"`
}func main() {
parser, _ := multiparser.New(parser.JSON, parser.YAML)// Parse JSON
var jsonObj object
_ = parser.Parse([]byte(`{"data": "data"}`), &jsonObj)
// Parse YAML
var yamlObj object
_ = parser.Parse([]byte(`data: data`), &yamlObj)
}
```### Supported parsers
- JSON - `encoding.json`
- YAML - `gopkg.in/yaml.v3`### Bring your own parser
All you have to do is implement `multiparser.Parser` interface, e.g.
```golang
type parser struct {}// Parse converts raw to object
func (p *parser) Parse(from []byte, to interface{}) error {
panic("implement me")
}
```