Skip to content

Force yaml (single) value output to have (single) quotes #351

Answered by bioball
StefMa asked this question in Q&A
Discussion options

You must be logged in to vote

Render directives are an escape hatch to get the renderer to do what you want.

Here's an example: this combines a render directive with an output converter to turn all strings into JSON strings, which is still valid YAML (YAML accepts JSON strings):

cron = "* * * * *"

local jsonRenderer = new JsonRenderer {}

output {
  renderer = new YamlRenderer {
    converters {
      [String] = (it) -> new RenderDirective { text = " " + jsonRenderer.renderValue(it) }
    }
  }
}

This produces:

cron: "* * * * *"

It'll be more work to produce strings with single quotes. If your goal is to have consistent looking strings, I'd just stick with double quotes here.

While this might be (I'm not 100% sure w…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@StefMa
Comment options

Answer selected by StefMa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants