Skip to content

Escaping Syntax #1

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

Open
mnot opened this issue May 8, 2014 · 3 comments
Open

Escaping Syntax #1

mnot opened this issue May 8, 2014 · 3 comments

Comments

@mnot
Copy link
Member

mnot commented May 8, 2014

(from an RFC Errata)

The escape syntax seems weird and confusing. Rather than ~0 and ~1, why not use a repeated (double) slash to escape a slash? This is similar to how SQL escapes single quotes in string literals by using the single quote twice.

We have JSON functions in Presto (prestodb.io) that could benefit from an improved syntax (they currently use JSONPath), but I can't see understanding ~0 and ~1.

@espadrine
Copy link

espadrine commented Aug 23, 2016

The double slash feels similarly weird.

I wish for JSON Patch 2 to allow having arrays as paths, circumventing the problem of escaping and making it much faster for machines to parse the path.

For instance, { "op": "add", "path": ["foo", "/", "~1"], "insert data here" } applied to {"foo": {"/": {}}} would result in {"foo": {"/": {"~1": "insert data here"}}}.

It is backwards-compatible, as libraries can detect whether the path is a string or an array.

@gregsdennis
Copy link

gregsdennis commented Feb 27, 2019

The escape syntax is well-established from JSON Pointer. Why are we looking to deviate?

they currently use JSONPath

JSON Path is a query syntax that has the potential to return multiple results. Many use cases for JSON Patch require a single result, for which JSON Pointer is much more well-suited.

The only time I could see wanting JSON Path is for when we explicitly want potentially multiple matches (like a SQL where clause).

(See also #23)


I agree with support for arrays as an option, however.

@streamich
Copy link

streamich commented Sep 3, 2020

+1 for using as array ["foo", "bar", 1] to specify the path. FWIW, my library—json-joy—supports Json Pointer as well as array syntax.

Array syntax is very useful for operations which are semantically very different for objects and arrays. For example "insert" operation is very different for objects and arrays, in object simply a new key is inserted, but in arrays all elements past insertion point are shifted.

When using an array as the path one can infer that if path step is a number it is indexing an array, if it is a string, it is referencing a key in object. That information is useful when doing operational transformation, when you need to transform one operation agains the other. Now if we use Json Pointer you basically need to see if the key step looks like a number, then it is likely that it is indexing an array and then one, kinda, can do the operational transform assuming the pointer is referencing an array, but it could also be completely wrong, if in reality the pointer is referencing an object with a key that looks like a number.


FWIW, Slate.js is using and array as a pointer. json1-ot is also using arrays.

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

4 participants