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

fix #52: allow enum keys when parsing tables #56

Merged
merged 10 commits into from
Mar 21, 2024

Conversation

pietroppeter
Copy link
Contributor

@pietroppeter pietroppeter commented Jan 6, 2023

currently jsony can only parse Table with string keys but I do not see any problem to allow a generic key enum should be fine too. this fixes #52. added two test case for enum, the second of which replicates issue #52 (enum key). edited to remove possibility of generic keys.

Copy link
Contributor

@ee7 ee7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently jsony can only parse Table with string keys but I do not see any problem to allow a generic key.

I think there is one: a JSON key must be a string. That is, {1: "a"} is invalid JSON.

See:

1

To illustrate with other tools:

$ echo '{1: "a"}' | jq
parse error: Object keys must be strings at line 1, column 3

Comment on lines 62 to 63
var s = """{1:"a"}"""
var v = s.fromJson(Table[int, string])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s is invalid JSON.

@pietroppeter
Copy link
Contributor Author

pietroppeter commented Jan 6, 2023

You are right, somehow I got convinced you could have any key (I am working on a yaml parser based on this, so things got mixed up ;)), thanks for the remark! I could fix to only allow string and enum as table keys. Suggestions welcome.

@pietroppeter pietroppeter changed the title fix #52: allow generic keys when parsing tables fix #52: allow enum keys when parsing tables Jan 6, 2023
@pietroppeter
Copy link
Contributor Author

fixed to restrict only to string and enum case.

@pietroppeter
Copy link
Contributor Author

Not sure if the CI failure (failure when testing with js backend) is related to this fix, at the moment I do not have node locally to test it.

@treeform
Copy link
Owner

I think your PR fails to due to issue: nim-lang/Nim#21317

@ringabout
Copy link

fixed => nim-lang/Nim#21320

@pietroppeter pietroppeter reopened this Feb 1, 2023
@pietroppeter
Copy link
Contributor Author

If CI is approved I would expect it to be green

@pietroppeter
Copy link
Contributor Author

CI is green and ready to merge if approved

tests/test_tables.nim Outdated Show resolved Hide resolved
@pietroppeter
Copy link
Contributor Author

sorry it took a while to address your comment, in the end the code was fine as it was but it took me a moment to realize that (see resolved comment above).

Copy link
Contributor

@ee7 ee7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the final lines more clear? LGTM otherwise.

tests/test_tables.nim Outdated Show resolved Hide resolved
@treeform treeform merged commit 0ce3952 into treeform:master Mar 21, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

Can't parse table with enum as a key
4 participants