Coder Social home page Coder Social logo

Comments (3)

dherman avatar dherman commented on August 30, 2024

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

from jsonselect.

lloyd avatar lloyd commented on August 30, 2024

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!

from jsonselect.

sayrer avatar sayrer commented on August 30, 2024

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. :)

from jsonselect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.