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

[writer]Surround string by double quote instead of simple #290

Closed
AlaricCalmette opened this issue Jun 3, 2016 · 5 comments
Closed

[writer]Surround string by double quote instead of simple #290

AlaricCalmette opened this issue Jun 3, 2016 · 5 comments

Comments

@AlaricCalmette
Copy link

AlaricCalmette commented Jun 3, 2016

I would like to be able to take a json object like this :

{
    translation:
        { 
            key: 'this_is_a_key',
            value: 'this is a value'
        }
}

and output a yml file like this :

- translation :
    key: "this_is_a_key"
    value: "this is a value"

I've tried several method but was only able to achieve either

- translation :
    key: this_is_a_key
    value: this is a value

or

- translation :
    key: '"this_is_a_key"'
    value: '"this is a value"'

note that in the latter this is not three quotes but a single quote followed by a double quote

Is there any way to do this with this module?

@dervus
Copy link
Collaborator

dervus commented Jun 3, 2016

There's no settings for this at the moment. The dumper tries to choose "minimal" possible scalar style to represent each particular string.

Ability to specify preferred scalar styles would be nice addition though. Contributions on this matter are welcomed.

@AlaricCalmette
Copy link
Author

Okay thanks for the answer, will see if i can contribute.

jpb added a commit to jpb/js-yaml that referenced this issue Oct 29, 2018
jpb added a commit to jpb/js-yaml that referenced this issue Oct 29, 2018
jpb added a commit to jpb/js-yaml that referenced this issue Oct 29, 2018
jpb added a commit to jpb/js-yaml that referenced this issue Oct 29, 2018
jpb added a commit to jpb/js-yaml that referenced this issue Oct 30, 2018
@xavier630
Copy link

Any news on this feature?

@ratacat
Copy link

ratacat commented Aug 29, 2019

I'd appreciate this too!

@rlidwka
Copy link
Member

rlidwka commented Dec 9, 2020

Fixed by 7b256d7 in dev branch, gonna be released later.

console.log(require('js-yaml').dump({ key: "this_is_a_key" }, { quotingType: '"', forceQuotes: true }))
// outputs:
// key: "this_is_a_key"

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

Successfully merging a pull request may close this issue.

5 participants