-
Notifications
You must be signed in to change notification settings - Fork 37
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
json2yaml line-wraps the output #5
Comments
I cannot reproduce this with Go 1.4.2 and the latest versions of the dependencies on Linux x86_64. Could you run this script in the repository with a built binary and tell me what it outputs for you? #!/bin/sh
set -e
cat >wrap.json <<END
{
"balanceHeld": {
"description": "Balance of the account held for transferring to other users (in cents)",
"type": "integer"
}
}
END
cat >wrap.reference.yaml <<END
balanceHeld:
description: Balance of the account held for transferring to other users (in cents)
type: integer
END
./remarshal -if=json -of=yaml -i=wrap.json > wrap.yaml
diff wrap.reference.yaml wrap.yaml && echo same
cp remarshal json2yaml
./json2yaml wrap.json > wrap.yaml
diff wrap.reference.yaml wrap.yaml && echo same
rm json2yaml |
I will first admit that I installed the binaries on OSX via However, add a bunch more text to the description field in your example, and it does the line wrapping: #!/bin/sh
set -e
cat >wrap.json <<END
{
"balanceHeld": {
"description": "Balance of the account held for transferring to other users (in cents) and then a bunch more text after that",
"type": "integer"
}
}
END
cat >wrap.reference.yaml <<END
balanceHeld:
description: Balance of the account held for transferring to other users (in cents) and then a bunch more text after that
type: integer
END
./remarshal -if=json -of=yaml -i=wrap.json > wrap.yaml
diff wrap.reference.yaml wrap.yaml && echo same
cp remarshal json2yaml
./json2yaml wrap.json > wrap.yaml
diff wrap.reference.yaml wrap.yaml && echo same
rm json2yaml The output from both diffs:
|
Right, I've reproduced it now. This appears to be an upstream bug: go-yaml/yaml#166. While I could fix the bug upstream, there is another problem with |
Thanks for looking into this! FWIW, in the interest of getting work done today, I found an node package that does what I needed: https://www.npmjs.com/package/json2yaml |
Ah, good. This alternative should be useful to whoever else runs into this bug until it is fixed. JavaScript sure does have well-maintained libraries for YAML and TOML. One strategy I'm considering for a rewrite is to package them in a static binary with Duktape, an embedded JS interpreter. This should be as convenient as the binaries built with Go. |
Python's libraries for TOML and YAML solve the problem of Remarshal not being able to process TOML newer than version 0.2 (#4) and at least some of the issues with the generated YAML (#2, #5). Floating point precision (#2) in all formats requires further investigation, though it seems that what PyYAML and pytoml do matches the respective specs. v0.4.0
Implemented in v0.5. Try
|
Part of my JSON file has the following:
json2yaml converts this to:
It looks like all long lines are being wrapped at 80 characters or so. But that line break that's being added in the
description
property is causing another tool to fail importing, because I don't think wrapping long lines like that results in a valid YAML file.Could you add a flag to prevent line wrapping? Or output long lines with the "pipe" notation:
The text was updated successfully, but these errors were encountered: