{"id":13481160,"url":"https://github.com/ghodss/yaml","last_synced_at":"2025-05-13T23:09:50.289Z","repository":{"id":23976474,"uuid":"27359298","full_name":"ghodss/yaml","owner":"ghodss","description":"A better way to marshal and unmarshal YAML in Golang","archived":false,"fork":false,"pushed_at":"2023-05-26T03:22:30.000Z","size":45,"stargazers_count":1051,"open_issues_count":35,"forks_count":232,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-10T21:02:42.862Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ghodss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-01T02:37:07.000Z","updated_at":"2025-04-25T02:36:06.000Z","dependencies_parsed_at":"2024-06-18T11:13:55.763Z","dependency_job_id":null,"html_url":"https://github.com/ghodss/yaml","commit_stats":{"total_commits":28,"total_committers":17,"mean_commits":"1.6470588235294117","dds":0.6785714285714286,"last_synced_commit":"d8423dcdf3440d0a5baffc6f90a11e4128545620"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghodss%2Fyaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghodss%2Fyaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghodss%2Fyaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghodss%2Fyaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghodss","download_url":"https://codeload.github.com/ghodss/yaml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254042288,"owners_count":22004891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:00:49.258Z","updated_at":"2025-05-13T23:09:45.271Z","avatar_url":"https://github.com/ghodss.png","language":"Go","funding_links":[],"categories":["开源类库","Go","Open source library"],"sub_categories":["配置","Construction"],"readme":"# YAML marshaling and unmarshaling support for Go\n\n[![Build Status](https://travis-ci.org/ghodss/yaml.svg)](https://travis-ci.org/ghodss/yaml)\n\n## Introduction\n\nA wrapper around [go-yaml](https://github.com/go-yaml/yaml) designed to enable a better way of handling YAML when marshaling to and from structs.\n\nIn short, this library first converts YAML to JSON using go-yaml and then uses `json.Marshal` and `json.Unmarshal` to convert to or from the struct. This means that it effectively reuses the JSON struct tags as well as the custom JSON methods `MarshalJSON` and `UnmarshalJSON` unlike go-yaml. For a detailed overview of the rationale behind this method, [see this blog post](https://web.archive.org/web/20150812020634/http://ghodss.com/2014/the-right-way-to-handle-yaml-in-golang/).\n\n## Compatibility\n\nThis package uses [go-yaml](https://github.com/go-yaml/yaml) and therefore supports [everything go-yaml supports](https://github.com/go-yaml/yaml#compatibility).\n\n## Caveats\n\n**Caveat #1:** When using `yaml.Marshal` and `yaml.Unmarshal`, binary data should NOT be preceded with the `!!binary` YAML tag. If you do, go-yaml will convert the binary data from base64 to native binary data, which is not compatible with JSON. You can still use binary in your YAML files though - just store them without the `!!binary` tag and decode the base64 in your code (e.g. in the custom JSON methods `MarshalJSON` and `UnmarshalJSON`). This also has the benefit that your YAML and your JSON binary data will be decoded exactly the same way. As an example:\n\n```\nBAD:\n\texampleKey: !!binary gIGC\n\nGOOD:\n\texampleKey: gIGC\n... and decode the base64 data in your code.\n```\n\n**Caveat #2:** When using `YAMLToJSON` directly, maps with keys that are maps will result in an error since this is not supported by JSON. This error will occur in `Unmarshal` as well since you can't unmarshal map keys anyways since struct fields can't be keys.\n\n## Installation and usage\n\nTo install, run:\n\n```\n$ go get github.com/ghodss/yaml\n```\n\nAnd import using:\n\n```\nimport \"github.com/ghodss/yaml\"\n```\n\nUsage is very similar to the JSON library:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/ghodss/yaml\"\n)\n\ntype Person struct {\n\tName string `json:\"name\"` // Affects YAML field names too.\n\tAge  int    `json:\"age\"`\n}\n\nfunc main() {\n\t// Marshal a Person struct to YAML.\n\tp := Person{\"John\", 30}\n\ty, err := yaml.Marshal(p)\n\tif err != nil {\n\t\tfmt.Printf(\"err: %v\\n\", err)\n\t\treturn\n\t}\n\tfmt.Println(string(y))\n\t/* Output:\n\tage: 30\n\tname: John\n\t*/\n\n\t// Unmarshal the YAML back into a Person struct.\n\tvar p2 Person\n\terr = yaml.Unmarshal(y, \u0026p2)\n\tif err != nil {\n\t\tfmt.Printf(\"err: %v\\n\", err)\n\t\treturn\n\t}\n\tfmt.Println(p2)\n\t/* Output:\n\t{John 30}\n\t*/\n}\n```\n\n`yaml.YAMLToJSON` and `yaml.JSONToYAML` methods are also available:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/ghodss/yaml\"\n)\n\nfunc main() {\n\tj := []byte(`{\"name\": \"John\", \"age\": 30}`)\n\ty, err := yaml.JSONToYAML(j)\n\tif err != nil {\n\t\tfmt.Printf(\"err: %v\\n\", err)\n\t\treturn\n\t}\n\tfmt.Println(string(y))\n\t/* Output:\n\tname: John\n\tage: 30\n\t*/\n\tj2, err := yaml.YAMLToJSON(y)\n\tif err != nil {\n\t\tfmt.Printf(\"err: %v\\n\", err)\n\t\treturn\n\t}\n\tfmt.Println(string(j2))\n\t/* Output:\n\t{\"age\":30,\"name\":\"John\"}\n\t*/\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghodss%2Fyaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghodss%2Fyaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghodss%2Fyaml/lists"}