matiso
I am building an API that needs to allow the user to download a yaml config file for an external application.
I’m not sure if I’m blind, or there is no Elixir library that converts a map (or struct) into YAML? All I can find is how to decode YAML and parse it into an Elixir data structure, but not the other way around.
Trending in Questions
Hello everyone!
I am new to coding with Elixir/Erlang. And i am looking for some utilities for fuzzing testing like AFL++.
Does anyone ...
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I load tested a plain Phoenix chat app backed by Postgres with 100 million messages in it, everything on default settings, to see what br...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #elixirconf-us
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #security
- #elixirconf-eu
- #processes
- #api
- #forms
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hubertlepicki
and there is a good reason for that: YAML is not a standardized format. In fact each and every implementation of YAML out there varies slightly. So when you generate YAML config file from most popular PHP library, it may or may not work as expected in most popular Ruby library etc.
I think @josevalim had a strong opinion on not using YAML in Elixir, and this sentiment has been picked up by the community, since the not any sort of standard argument is really good one. As a result we have a few parsers, since reading some legacy config files may be necessary - and no generators that I can see.
I’d probably generate some intermediate data format from my data (JSON?) and convert it to YAML with some external to Elixir tool (Ruby?).
NobbZ
By the book json is a subset of yaml, so if your clients yank parser adheres to the yaml standard, it will work…
matiso
You see, CSV happens to be implemented in the wildest ways, yet if customers / stakeholders of my project require a CSV export, they won’t be happy with an answer like yours.
I can understand that José does not want to use YAML FOR Elixir (e.g. he said you should not use it for Elixir configuration, and I totally agree with that). My use case is a different one. I’m building an API that needs to return a YAML file, because it is needed as a config for a separate application that I cannot change.
This, in my books, would qualify as an ugly workaround. Now I can’t say in the docs: “just
curl https://foo/bar.yml > bar.yml” and you’re done! Now I’d need to deliver a script or tool to make the conversion and have the user possibly have the required runtime (or use Go, but then you have to publish a binary for every major desktop OS).All this discussion about YAML being terrible is nice and entertaining, until you hit the real world. I’m not yet convinced of why not having a YAML generator in Elixir might be a good idea.
OvermindDL1
Yep, this is about the only thing that all YAML parsers should agree on, that they can take normal JSON too, after that they diverge all crazy, see:
https://github.com/cblp/yaml-sucks
Among many many others.
Really though, the YAML ‘spec’ is horrible beyond horrible, do not use it, do not look at it, ignore that utter crap.
JSON is not bad, bit wordy, but not bad.
I quite like TOML and HOSON both (for different purposes), but JSON is basically the standard.
I thought CSV was actually quite well defined, proper cell encapsulation and escapaing and all?
But he is right, one YAML file that works in one YAML importer may not work in another (see the yaml-sucks github link above, it tests those).
Just export JSON then, YAML can read JSON no problem. JSON is a subset of YAML so it not like it is some random addon to it, valid JSON is valid YAML.
Good luck with that, almost every YAML library gets it wrong so which do you want to base it on? Or do you want to write it from scratch in Elixir/Erlang itself, and if so dang good luck there, the YAML spec is utterly monstrous and you are near guaranteed to get a lot of it wrong because it has a lot of undefined behaviour…
hubertlepicki
OK. I was trying to give you the bigger picture on why you can’t find a library you need. I guess that’s not welcome. Good luck, mate! But most likely you need to write your own. Do publish it, there are other people who can benefit.
matiso
On the contrary! I’m very happy to get your feedback, and I always try to keep an open mind. And you are right: there is a reason YAML is considered bad for the lack of a proper specification. I’m aware of that. I was just trying to point out that, sometimes, you just need to implement a specific solution, you like it or not.
My takeaway from this discussion is that I should try using JSON as the response format and post-process it if there really is no other way around generating YAML. Thanks for the feedback!
michalmuskala
Valid JSON is valid YAML. Any conforming YAML parser should be able to parse JSON. So if you don’t have any specific needs for the YAML format, doing something like:
will produce something any YAML parser will be able to process.
50kudos
Sorry to continue here. @matiso what you ended up with, or now 2019 have you found a solution? I have a very strict requirement that is editing yaml and put it back (cry)
Would love to hear from you all.
yoran
@50kudos For what it’s worth, I found myself in a similar situation. I could parse YAML with yaml-elixir but didn’t have a way to write. So I wrote a short YAML writer myself.
You use it as follows:
It’s not perfect but it suits my purposes (reading and writing the
app.yamlconfiguration file in Google App Engine).Thought I’d share to help others who come here while searching, like I did!
mruoss
https://github.com/ufirstgroup/ymlr