https://github.com/nidu/vscode-copy-json-path
VSCode extension: copy path to current json node
https://github.com/nidu/vscode-copy-json-path
json-path vscode
Last synced: 5 months ago
JSON representation
VSCode extension: copy path to current json node
- Host: GitHub
- URL: https://github.com/nidu/vscode-copy-json-path
- Owner: nidu
- License: mit
- Created: 2016-11-23T20:06:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-03-15T22:04:16.000Z (over 2 years ago)
- Last Synced: 2024-03-15T22:47:34.578Z (over 2 years ago)
- Topics: json-path, vscode
- Language: TypeScript
- Homepage:
- Size: 94.7 KB
- Stars: 18
- Watchers: 2
- Forks: 4
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# copy-json-path
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.
## Using
Launch command `Copy Json Path` from command palette or context menu.
## Configuration
- `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 path `a.b-c` instead of `a[\"b-c\"]` for example. If you want all keys to be escaped - use regex that doesn't match anything, e.g. single space ` ` will only match single space, which is very rare object key (you can go more complicated like `a{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 is `false`.
- `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 `.`.
## Linux dependency
xclip
## Change Log
### 0.4.0
- Add option `pathSeparator` to control path separator
### 0.3.0
- Add the option to put the file name in the returned path (@olivier-deschenes, #15)
### 0.2.1
- Add info on regex for all keys to be escaped for `nonQuotedKeyRegex` (see issue #13)
### 0.2.0
- Allow custom non quoted key regex (see issue #6)
### 0.1.1
- Use vscode clipboard API for copy (@amoshydra)
- Update dependencies
### 0.1.0
- Added context menu command (@mamoruuu)
### 0.0.5
- Fix JSON check function
### 0.0.4
- Better JS support
- Using acorn parser so valid JS is expected
### 0.0.3
- Less broken JS object support
- Fix when getting path before key like `{a: {# b: 3}}`
- Audit fix
### 0.0.2
- 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)
### 0.0.1
Initial release.