ConvertFrom-JSON does not support underscores or hyphens (or any other non-word characters) in property names or values


CouchDB outputs JSON strings with internal properties such as the document ID and revision prefixed with an underscore. Furthermore, the revision property's value will always contain a hyphen, as CouchDB revisions are in the form "<revision number>-<hex string>". The following JSON string is an example document from CouchDB.
ConvertFrom-JSON does not allow underscores or hyphens to appear in property names or values, whilst ConvertTo-JSON is more lenient and will appear to correctly parse anything that is thrown at it. The attached patch file resolves this issue for ConvertFrom-JSON.
It appears from the JSON specification (http://www.json.org/) that property names and values can be made up of any Unicode character excluding control characters, " (double-quotes) and \ (backslash). Having attempted to implement this myself, this is mostly trivial; however, correctly handling the escape characters require some lookahead to be built into the parser.

file attachments


dfinke wrote May 1, 2010 at 12:58 PM

Thanks for looking into this and the patch.

dfinke wrote May 1, 2010 at 12:59 PM

Thanks for looking into this and the patch.

wrote Feb 14, 2013 at 7:31 PM