https://github.com/markrosemaker/yaml
https://github.com/markrosemaker/yaml
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/markrosemaker/yaml
- Owner: MarkRosemaker
- Created: 2025-01-14T19:27:30.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-14T21:10:17.000Z (over 1 year ago)
- Last Synced: 2025-01-22T07:17:28.977Z (over 1 year ago)
- Language: Go
- Size: 493 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# YAML Marshalling and Unmarshalling
This repository provides functionality for YAML marshalling and unmarshalling similar to [JSON v2](https://pkg.go.dev/encoding/json/v2). It allows users to use the same JSON options they would use for JSON v2 to encode and decode YAML.
## Features
- Marshal Go structs to YAML
- Unmarshal YAML to Go structs
- Support for JSON v2 options
## Installation
To install the package, use the following command:
```sh
go get github.com/MarkRosemaker/yaml
```
## Usage
Here is a basic example of how to use the package:
```go
package main
import (
"fmt"
"github.com/MarkRosemaker/yaml"
)
type Example struct {
Name string `json:"name"`
Age int `json:"age"`
}
func main() {
ex := Example{Name: "John Doe", Age: 30}
// Marshal to YAML
yamlData, err := yaml.Marshal(ex)
if (err != nil) {
fmt.Println("Error marshalling to YAML:", err)
return
}
fmt.Println("YAML Data:", string(yamlData))
// Unmarshal from YAML
var ex2 Example
err = yaml.Unmarshal(yamlData, &ex2)
if (err != nil) {
fmt.Println("Error unmarshalling from YAML:", err)
return
}
fmt.Println("Unmarshalled Struct:", ex2)
}
```
## JSON v2 Options
This package supports the same options available in JSON v2 for encoding and decoding. You can use json struct tags to customize the YAML output just as you would with JSON.
## Contributing
Contributions are welcome! Please open an issue or submit a pull request.
## License
This project is licensed under the MIT License.