Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to omit space between array elements #346

Closed
felixfbecker opened this issue May 6, 2017 · 4 comments
Closed

Option to omit space between array elements #346

felixfbecker opened this issue May 6, 2017 · 4 comments

Comments

@felixfbecker
Copy link

We like to encode objects and arrays to query parameters using YAML. The parser is able to parse this correctly:

image

But unfortunately, the dumper always adds unneeded spaces between array elements:

image

We don't encode [] for prettiness and browsers can handle them fine (PHP has used them forever), but spaces of course do need to be encoded, which is not very pretty.

Here are the options I am currently using to output single line YAML:

yaml.safeDump(value, { flowLevel: 0, indent: 0, lineWidth: Infinity, noCompatMode: true, sortKeys: true })

It would be great to have an option for omitting these non-required spaces / emitting "minimized" YAML.

@puzrin
Copy link
Member

puzrin commented May 6, 2017

IMHO that's a madness to use yaml parser/dumper such way :). It's not intended for URL encoding. Goal of dumper is to create pretty human-readable result. May be it creates something close to your wishes... by accident... but that's not enougth to add as official option.

I tend to reject as "out of project scope", but if i miss something important, please explain.

@felixfbecker
Copy link
Author

felixfbecker commented May 6, 2017

Well, what is the project scope? According to the readme:

This is an implementation of YAML, a human-friendly data serialization language.

Good applications should have readable, human friendly URLs, at the same time complicated applications have complicated data to serialize in the URL. A clear use case for a human-friendly data serialization language.

Basic key=value encoding doesn't fill that need, the data model is too basic. Some applications use styles like array[]=1&array[]=2 to encode nested structures but that bloats quickly and doesn't achieve the goal of good readability.

JSON can encode nested data, but results in bloated output and lots of reserved characters because of the required quotes everywhere.

YAML sits perfectly in-between, supporting all data structures of JSON with the simplicity of basic, unquoted key=value pairs.

It fits directly into the project scope imo. It doesn't create something close to what I want by accident, it creates something close to what I want because what I want (a human friendly yet powerful data serialisation) is exactly what this project offers (a human friendly yet powerful data serialisation) 🙂

I understand that you don't want to commit to maintaining a lot of code for rare use cases, but I imagine the implementation and maintenance cost of this to be minimal. There are already great options to control the line breaking behaviour, I don't think an option to omit the added space in this single case (array elements) would hurt.

@puzrin
Copy link
Member

puzrin commented May 7, 2017

Ok, PR with condensed flow mode support will be accepted.

@puzrin
Copy link
Member

puzrin commented May 20, 2017

Closing to keep tracker clear. But if anyone decide to create PR - that will be accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants