{"id":13509774,"url":"https://github.com/KamilLelonek/yaml-elixir","last_synced_at":"2025-03-30T14:31:41.471Z","repository":{"id":35610551,"uuid":"39883984","full_name":"KamilLelonek/yaml-elixir","owner":"KamilLelonek","description":"Yaml parser for Elixir based on native Erlang implementation","archived":false,"fork":false,"pushed_at":"2024-06-27T11:01:04.000Z","size":271,"stargazers_count":174,"open_issues_count":0,"forks_count":34,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-18T17:59:02.290Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KamilLelonek.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":"2015-07-29T09:03:44.000Z","updated_at":"2025-01-09T05:59:18.000Z","dependencies_parsed_at":"2024-06-18T13:47:51.435Z","dependency_job_id":"e194261c-c4e6-450e-9b40-ea10a3ae28e6","html_url":"https://github.com/KamilLelonek/yaml-elixir","commit_stats":{"total_commits":129,"total_committers":21,"mean_commits":6.142857142857143,"dds":0.3798449612403101,"last_synced_commit":"95bb3ce27c39127bb8cbc50291b1fe6db6933e0f"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fyaml-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fyaml-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fyaml-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KamilLelonek%2Fyaml-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KamilLelonek","download_url":"https://codeload.github.com/KamilLelonek/yaml-elixir/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246332199,"owners_count":20760435,"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-08-01T02:01:12.836Z","updated_at":"2025-03-30T14:31:40.999Z","avatar_url":"https://github.com/KamilLelonek.png","language":"Elixir","funding_links":[],"categories":["YAML"],"sub_categories":[],"readme":"# YAML Parser for Elixir\n\n[![Build Status](https://travis-ci.org/KamilLelonek/yaml-elixir.svg)](https://travis-ci.org/KamilLelonek/yaml-elixir)\n[![Module Version](https://img.shields.io/hexpm/v/yaml_elixir.svg)](https://hex.pm/packages/yaml_elixir)\n[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/yaml_elixir/)\n[![Total Download](https://img.shields.io/hexpm/dt/yaml_elixir.svg)](https://hex.pm/packages/yaml_elixir)\n[![License](https://img.shields.io/hexpm/l/yaml_elixir.svg)](https://github.com/KamilLelonek/yaml-elixir/blob/master/LICENSE)\n[![Last Updated](https://img.shields.io/github/last-commit/KamilLelonek/yaml-elixir.svg)](https://github.com/KamilLelonek/yaml-elixir/commits/master)\n\nThis is a wrapper for [yamerl](https://github.com/yakaz/yamerl) - a native Erlang `YAML` parser which brings all of the functionalities to Elixir language.\n\n## Installation\n\nAdd `:yaml_elixir` as a dependency in your `mix.exs` file.\n\n```elixir\ndefp deps do\n  [\n     # ...\n    {:yaml_elixir, \"~\u003e x.x\"},\n  ]\nend\n```\n\nWhere `x.x.x` equals the version in [`mix.exs`](mix.exs) (you can omit the last `x`). **Always make sure to use the latest version**.\n\nOnce you've done that, run `mix deps.get` in your command line to fetch the dependency.\n\n## Usage\n\nWith `YamlElixir` you have an access to two functionalities: one for parsing a string and an another one for parsing a file.\n\nRun `iex -S mix` in your terminal to try how their works.\n\n### Parsing a string\n\n```elixir\nyaml = \"\"\"\n  a: a\n  b: 1\n  c: true\n  d: ~\n  e: nil\n\"\"\"\n\"  a: a\\n  b: 1\\n  c: true\\n  d: ~\\n  e: nil\\n\"\nYamlElixir.read_from_string(yaml)\n{:ok, %{\"a\" =\u003e \"a\", \"b\" =\u003e 1, \"c\" =\u003e true, \"d\" =\u003e nil, \"e\" =\u003e \"nil\"}}\n```\n\n### Parsing a file\n\n```elixir\npath = Path.join(File.cwd!(), \"test/fixtures/flat.yml\")\n\"/Users/KamilLelonek/Development/yaml-elixir/test/fixtures/flat.yml\"\nYamlElixir.read_from_file(path)\n{:ok, %{\"a\" =\u003e \"a\", \"b\" =\u003e 1, \"c\" =\u003e true, \"d\" =\u003e nil, \"e\" =\u003e []}}\n```\n\n### Support for atoms\n\nBy default, all map keys are processed as strings, as are all bareword or quoted\nvalues.\n\nIf you prefer to autodetect keys and values that begin with `:` as atoms, this can be accomplished by passing `atoms: true` as an option to any of the `read_*` functions.\n\n```elixir\nyaml = \"\"\"\n  a: a\n  b: 1\n  c: true\n  d: ~\n  e: nil\n  :f: :atom\n\"\"\"\n\"  a: a\\n  b: 1\\n  c: true\\n  d: ~\\n  e: nil\\n\"\nYamlElixir.read_from_string(yaml, atoms: true)\n{:ok, %{:f =\u003e :atom, \"a\" =\u003e \"a\", \"b\" =\u003e 1, \"c\" =\u003e true, \"d\" =\u003e nil, \"e\" =\u003e \"nil\"}}\n```\n\nAtoms are not garbage collected by `BEAM`, so be careful with this option, and\ndon't use it with user-supplied input.\n\nIf you enable autodetection of atoms, any string values entered (e.g. `\":not_really_an_atom\"`) will be converted to atoms, as well. If you only need to support a few atom values, it _might_ be better to enable `yamerl's` custom tag for atoms:\n\n```elixir\n:yamerl_app.set_param(:node_mods, [:yamerl_node_erlang_atom])\n```\n\nand then using the somewhat inconvenient syntax for it:\n\n```yaml\natom_key: !\u003ctag:yamerl,2012:atom\u003e atom_value\n```\n\n### Support for keyword lists\n\nKeyword lists can be returned in two ways. Either all maps can be transformed into keyword\nlists via the option `maps_as_keywords: true` or individually with a tag. To mark a block\nas a keyword list you must first pass in the node module which can process the tokens:\n\n```elixir\n:yamerl_app.set_param(:node_mods, [YamlElixir.Node.KeywordList])\n```\n\nand then tag the desired block:\n\n```yaml\nprod:\n  foo: !\u003ctag:yaml_elixir,2019:keyword_list\u003e\n    foo: bar\n    bar: foo\n```\n\nThis will return:\n\n```elixir\n%{\"prod\" =\u003e %{\"foo\" =\u003e [{\"bar\", \"foo\"}, {\"foo\", \"bar\"}]}}\n```\n\nNote that due to a quirk in how `yamerl` parses YAML documents, using the flow style with\nthis tag will not work. Do not expect your document to be processed if you write your\nYAML like this:\n\n```yaml\nprod:\n  foo: !\u003ctag:yaml_elixir,2019:keyword_list\u003e {foo: bar, bar: foo}\n```\n\n### Elixir Sigil\n\nThe `YamlElixir.Sigil` module provides the `~y` sigil that can be useful for example for keeping short configurations or other inlined YAML.\n\n```elixir\nimport YamlElixir.Sigil\n\n@config ~y\"\"\"\ndebug: false\nport: 9200\nfiles:\n  - some/file.csv\n  - another/file.csv\n\"\"\"\n```\n\nUse the `a` sigil modifier to turn on atom values from YAML:\n\n```elixir\n~y\":answer: yes\"a\n```\n\nYou can find more examples in [`test` directory](https://github.com/KamilLelonek/yaml-elixir/blob/master/test/yaml_elixir_test.exs).\n\n### Merging anchors\n\nIn case your YAML contains [anchors](http://blogs.perl.org/users/tinita/2019/05/reusing-data-with-yaml-anchors-aliases-and-merge-keys.html), you can have these resolved by passing `merge_anchors: true`:\n\n```elixir\nyaml = \"\"\"\n  foo: \u0026foo\n    bar: 42\n  baz:\n    \u003c\u003c: *foo\n\"\"\"\n\"  foo: \u0026foo\\n    bar: 42\\n  baz:\\n    \u003c\u003c: *foo\\n\"\nYamlElixir.read_from_string(yaml, merge_anchors: true)\n```\n\nwill result in\n\n```elixir\n%{\"yaml\" =\u003e %{\"foo\" =\u003e %{\"bar\" =\u003e 42}, \"baz\" =\u003e %{\"bar\" =\u003e 42}}}\n```\n\n## Mix tasks\n\nSometimes, you may want to use `yaml_elixir` in your `mix` tasks. To do that, you must ensure that the application has started.\n\n    Application.ensure_all_started(:yaml_elixir)\n\nAfter that, you will be able to use `:yaml-elixir` in your `mix` tasks.\n\n## Contribution\n\nIn case of any problems or suggestions do not hesitate and create a pull request.\n\n### Credits\n\n- [bobbypriambodo](https://github.com/bobbypriambodo)\n- [Hajto](https://github.com/Hajto)\n- [sambooo](https://github.com/sambooo)\n- [ernie](https://github.com/ernie)\n- [sibsibsib](https://github.com/sibsibsib)\n- [vic](https://github.com/vic)\n- [rothsberg](https://github.com/rothsberg)\n- [msimonborg](https://github.com/msimonborg)\n- [mononym](https://github.com/mononym)\n- [EugeneOsadchyi](https://github.com/EugeneOsadchyi)\n- [TylerPachal](https://github.com/TylerPachal)\n- [kianmeng](https://github.com/kianmeng)\n- [floriank](https://github.com/floriank)\n- [coryodaniel](https://github.com/coryodaniel)\n- [simonmcconnell](https://github.com/simonmcconnell)\n\n## Copyright and License\n\nCopyright (c) 2022 Kamil Lelonek\n\nThis library is MIT licensed. See the\n[LICENSE](https://github.com/KamilLelonek/yaml-elixir/blob/master/LICENSE.txt) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKamilLelonek%2Fyaml-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKamilLelonek%2Fyaml-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKamilLelonek%2Fyaml-elixir/lists"}