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

order based pseudo classes shouldn't match object children. #1

Closed
lloyd opened this issue May 21, 2011 · 3 comments
Closed

order based pseudo classes shouldn't match object children. #1

lloyd opened this issue May 21, 2011 · 3 comments

Comments

@lloyd
Copy link
Owner

lloyd commented May 21, 2011

Rob Sayre mentioned a flaw in the design of JSONSelect. Specifically that there in not a reliable and widely implemented method of normalizing property order in JSON objects.

The fallout of this is that the application of order dependant pseudo classes (like :first-child, :nth-child(), etc), can be unreliable and can vary depending on the serialization of the object.

This should result in two changes to JSONSelect:

  1. order based pseudo classes shouldn't match object children -- I argue that arrays are typically used where order is important (like for drink preferences ;)
  2. The depth first post-order traversal requirement I wanted to place on implementations should become a recommendation.

NOTE: Brendan Eich mentions that a tighter definition about canonical property order is in progress, but in order for JSONSelect to be immediately useful, I still think ripping this feature out is the right thing to do.

Gonna leave this bug open for a bit for thoughts....

@dherman
Copy link

dherman commented May 21, 2011

Fixing enumeration order of JS objects won't affect the "semantics" of JSON, because JSON has no semantics. It's just a grammar. So Rob's example from Python would still be relevant.

Note that this is a fantastic example of why semantics matters. Should objects be treated as ordered? Well, the spec informally claims in its introduction that "an object is an unordered collection of zero or more name/value pairs" but it never actually specifies this anywhere.

Dave

@lloyd
Copy link
Owner Author

lloyd commented May 22, 2011

That's right, even if we built normalization into jsonselect implementations, they would be re-ordering json on the wire and the order-dependent pseudo classes available to users have even less value.

My proper course of action stills seems to be to say order based pseudo classes shouldn't match object children.

Anyone who serializes JSON with meaning applied to object key order deserves what they get!

@sayrer
Copy link

sayrer commented May 22, 2011

Yes, they would be re-ordering JSON on the wire. Exactly.

But it gets worse. :)

You don't need any order-based selectors: just use numeric keys, always. They work for objects and arrays. Imagine this JS shell session:

var x = {"42":"foo"}
var y = []
y[42] = "foo"
foo
y["42"]
foo
x["42"]
foo

So, one time, I went down this path in https://github.com/sayrer/json-sync , but with more of an XPath flavor. I think Crockford also digs something similar: JSONPath. See http://www.crockford.com/misty/json.html

I can see why your way is something of a hit, what with the JQuery synergy. One thing I've learned is that Resig's way will always be more popular than anything I make up. :)

@lloyd lloyd closed this as completed in bcc8592 May 25, 2011
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

3 participants