Cannot ecape quotes correctly in yaml out of pkgs.formats.yaml

Hi. I am trying to modify my homepage instance services.homepage-dashboard.services.
This option uses pkgs.formats.yaml on the backend to generate a yaml file.
I need this yaml file to be in the format:

fields: ["wanted", "queued"]

I write double single quote to try and escape the string

 fields = ''["wanted", "queued"]'';

However this gives my single quotes on the outside.

fields: '["wanted", "queued"]'

What is the correct way to escape this string?

fields = "[${"wanted"}, ${"queued"}]";
 fields: '[wanted, queued]'

This Still has the single quote and no double quotes

fields = "[" + ''"wanted", "queued"'' + "]";
fields: '["wanted", "queued"]'

A Nix string will be a YAML string. I’m not sure why you’d expect otherwise.

Because nix strings like:

 href = "http://localhost/";

becomes yaml:

href: http://localhost/

Which does not have the single quotes.

Have you tried this?

href = "'https://foo.bar'";
fields = "['wanted', 'queued']";

aka. single quotes within double quotes?

input

fields = "['wanted', 'queued']";

output

fields: '[''wanted'', ''queued'']'
1 Like

That value is a YAML string. Quotes are optional, depending on the characters of the value.

You are right and all of this was for nothing.
I tried to use:

 fields = ''["wanted", "queued"]'';

and that work I do not know why it did not work before. silly me.
The application did not care about the single quote around the brackets.
Thank you all.

1 Like