Copy path to selected JSON or JS node as string.
Path parts are concatenated with . or wrapped with [""] for object keys and wrapped in [] for array indices.
Example:
For state like this (cursor position is bold)
{"a": ["q", {"k": 1}, 1]}
Path would be a[1].k.
For JS like this
var a = {"b": {c: 4, daq: [5, 15]}}
var b = {q: [2, 1**2**]}
Path would be q[1].
NOTE: JS objects are not validated.
Launch command Copy Json Path from command palette or context menu.
-
extension.copyJsonPath.nonQuotedKeyRegex: regex that tests whether key in path can be used without quotes. If key matches - key is not quoted. Use it if you want to have patha.b-cinstead ofa[\"b-c\"]for example. If you want all keys to be escaped - use regex that doesn't match anything, e.g. single spacewill only match single space, which is very rare object key (you can go more complicated likea{1000}). Default is^[a-zA-Z$_][a-zA-Z\\d$_]*$. -
extension.copyJsonPath.putFileNameInPath: boolean to set if the file name should be in the path. Default isfalse. -
extension.copyJsonPath.prefixSeparator: string separator to put between the prefix and the path. Default is:. -
extension.copyJsonPath.pathSeparator: string separator to put between the parts of the path. Default is..
xclip
- Add option
pathSeparatorto control path separator
- Add the option to put the file name in the returned path (@olivier-deschenes, #15)
- Add info on regex for all keys to be escaped for
nonQuotedKeyRegex(see issue #13)
- Allow custom non quoted key regex (see issue #6)
- Use vscode clipboard API for copy (@amoshydra)
- Update dependencies
- Added context menu command (@mamoruuu)
- Fix JSON check function
- Better JS support
- Using acorn parser so valid JS is expected
- Less broken JS object support
- Fix when getting path before key like
{a: {# b: 3}} - Audit fix
- Single quoted and unquoted keys are allowed
- Can copy path in js objects (expects valid js, no check for validity)
- Dont validate JSON on start because we wanna call it from js
- Path is also copied when cursor stands to the left of key (could return error before)
Initial release.