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

YAML Specific symbols support: .inf, .nan, ~, and multi-documents #24

Open
jkulvich opened this issue May 17, 2023 · 6 comments
Open

YAML Specific symbols support: .inf, .nan, ~, and multi-documents #24

jkulvich opened this issue May 17, 2023 · 6 comments

Comments

@jkulvich
Copy link

I have looked inside this repo to find if it able to convert some YAML specific symbols like .inf, .-inf, .nan, and ~.
In one of my own projects, when I have needed to same conversion from YAML to JSON it was resolved as:

  • .inf = 2147483647 (math.MaxInt32)
  • -.inf = -2147483648 (math.MinInt32)
  • .nan = 0
  • ~ = null

And what about YAML multi-document files?
It might be 2 functions where first will fetch only first document (by compatibility reasons) and processes it as JSON, and second fetches all documents and returns array of JSON converted docs.

@bronze1man
Copy link
Owner

some examples?

@jkulvich
Copy link
Author

jkulvich commented May 19, 2023

some examples?

According to the YAML Spec 1.2.2 section "10.2.1.4. Floating Point", and "2.2. Structures".

Input YAML:

key1: .inf
key2: .nan
key3: ~
---
key4: Second
key5: Document

Output JSONs:

{
  "key1": 2147483647,
  "key2": 0,
  "key3": null
}
{
  "key4": "Second",
  "key5": "Document"
}

@bronze1man
Copy link
Owner

you change the value of the data, it not looks good for me. (I know json do not allow +Inf/-Inf/Nan )

@jkulvich
Copy link
Author

you change the value of the data, it not looks good for me. (I know json do not allow +Inf/-Inf/Nan )

You made this great Go lib, thank you.
Anyway, I would like to use converter without any worries about unsuported YAML-to-JSON values.
Right now, I can't be sure about successful convert even if I have valid YAML.

It's always up to you. But this lib might be better with this little changes. Maybe, it can be applied as an additional optional parameters for converter function to force convert YAML specific symbols?

@bronze1man
Copy link
Owner

Thanks for your example. I will make it convertible.
I think we should make any valid yaml example convertible to valid json and document any abnormal staff. (like golang/go#59627)

@bronze1man
Copy link
Owner

.inf .nan ~ Supported in v1.3.2
v1.3.2 will translate .inf to "+Inf" .nan to "NaN" ~ to null in order to not loss any value infomation. (but will lose type infomation...)

In future version (may be tag as v1.3.3):

  • Add an option to match the behavior to what your asked here .
  • Add an option to match the behavior to returns array of JSON converted docs. (YAML stream to JSON array #19)
  • Add an option to match the behavior to returns first yaml object.

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