Filter JSON
Simple JSON Object and Array filter.
Features
- Filter JSON that contains comments.
- Filter Values
- Filter Attributes
- Filter Non Empty values
- Filter only Strings, Arrays, Numbers, Objects, Booleans
- Do Custom Filter.
- Filter Object
- Filter List items
- Filter Collections
Usage
- Right click on a file and select
Filter Values command to filter json based on List Filter Types values.
- Select the json object you need to filter and right click and select
Filter Values command to filter the selected json object.
- Select
Filter Attributes command to filter Object keys.
- Filtering Type :
NonEmpty , Boolean , Strings , Numbers , Arrays , Object .
- Custom Filter shows a quick pick items where we can provide our own custom logic to filter the data.
Custom Filter
- Right click on a file and select
Do Custom Filter command from Filter JSON submenu.
- A quick pick items shows up where we can provide our own custom logic to filter the data.
- We can also save our custom filter codes in settings using
filter-json.settings.customFilters vscode settings which will shows up in the quick pick items.
- Please use conditional operators to filter with multiple conditions.
Filter Array
- predefined variables
item , key , val , value , x is equal to a .
_ , lodash , dash - Lodash is exposed.
- Checks
isArray , isList will be true in array filter order
isObject will be false in array filter order
isAllNumber - returns true if all the items in a list are numbers
isAllString - returns true if all the items in a list are string
isAllList - returns true if all the items in a list are list
isAllObject , isCollection - returns true if all the items in a list are objects
- examples:
// filter Truthy values
[ "", "Hi", 1, 0, false, true, [], {}, null ]
// filter code = Boolean(a)
// filter to [ "Hi", 1, true, [], {} ]
// filter only string
[ "", "Hi", 1, 0, false, true, [], {}, null ]
// filter code = _.isString(item) or typeof item === "string"
// filter to [ "", "Hi"]
Filter Object
predefined variables
key - Object first key
val , value - Object first value
item - { key: key , val: val , value: val }
a , x is equal to item
_ , lodash , dash - Lodash is exposed.
Checks
isArray , isList will be false in object filter order
isObject will be true in object filter order
isAllNumber - returns true if all the values in a object are numbers
isAllString - returns true if all the values in a object are string
isAllList - returns true if all the values in a object are list
isAllObject , isCollection - returns true if all the values in a list are objects
examples:
// filter by keys
{ "name": "first item", "id": 1, "label": "foo" }
// filter code = ["name", "id"].includes(key)
// filter to { "id": 1, "name": "first item" }
// filter by value length
{ "name": "foo", "id": 1, "label": "first item" }
// filter code = isAllString ? val === "foo" : true
// filter to { "name": "foo" }
Enjoy!
| |