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

types in keys instead of values? #28

Closed
wbolster opened this issue Nov 2, 2016 · 3 comments
Closed

types in keys instead of values? #28

wbolster opened this issue Nov 2, 2016 · 3 comments

Comments

@wbolster
Copy link

wbolster commented Nov 2, 2016

have you considered storing types in keys instead of values? if so, what was the reason not to use that? pros are it would avoid string copying because of substring slicing in many languages (before decoding), and the tag would live on the "structure level" (the keys), not the "value level".

{
    "someint:i": "..."
}

(it would not allow for mixed content arrays of strings but that is bad anyway for other reasons.)

@tarcieri
Copy link
Contributor

tarcieri commented Nov 2, 2016

The main problem with this approach is the handling of arrays. Presently the root symbol of the grammar allows both objects and arrays as nonterminals. This syntax is incompatible with toplevel arrays, as they wouldn't carry any type information.

A potential solution to that is to disallow toplevel arrays and require them to be wrapped in an object. The type information encoded in the key would apply to all members of an array. (Sidebar: homogeneity of types in non-scalars is discussed in #23)

This still doesn't resolve the issue for nested arrays, however. Perhaps arrays could carry some type information in their first member, an approach suggested by @benlaurie in #22.

@tarcieri
Copy link
Contributor

tarcieri commented Nov 3, 2016

I created a concrete proposal for this approach here: #30

@tarcieri
Copy link
Contributor

tarcieri commented Nov 4, 2016

Fixed in #35

@tarcieri tarcieri closed this as completed Nov 4, 2016
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