lloyd / JSONSelect

CSS-like selectors for JSON
http://jsonselect.org
ISC License
1.59k stars 116 forks source link

Matching properties with reserved names #17

Closed chrismytton closed 13 years ago

chrismytton commented 13 years ago

I am testing JSONSelect against some activity streams json. The activity streams specification defines an object property in the json.

When I try to match the selector .object .objectType I am getting string required after ..

It seems that object is a reserved word for type selectors. I'm hoping a change to this regular expression will solve the problem, but I'm not sure what?

lloyd commented 13 years ago

You may use quotes around property names to both force them to be interpreted as strings and to include chars like spaces and control chars that are allowable by the json spec:

."object" .objectType

Going to leave this open though, it seems like the js parser could disambiguate given context.

chrismytton commented 13 years ago

Awesome! Thanks for the quick response.

Also worth noting that it seems that the same error occurs when the reserved name is used as part of the property name, so your example would have to be written as:

."object" ."objectType"
chrismytton commented 13 years ago

Actually I'm getting invalid json string when using the above selector? Not sure if that is related to the previous issue though?

This selector also gives the same error:

."name" ."first"
lloyd commented 13 years ago

oh, that's no good. I'll add a test or two and check it out...