An open API service indexing awesome lists of open source software.

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

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.