From 15def43e6cbd63b713d0040294c41998ec5ccced Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Tue, 29 Jun 2021 03:49:49 +0200 Subject: [PATCH] chore: adds JSONPath Plus docs (#1694) Co-authored-by: Nauman --- docs/getting-started/3-rulesets.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/getting-started/3-rulesets.md b/docs/getting-started/3-rulesets.md index 00e88105c7..b4bf91d1a1 100644 --- a/docs/getting-started/3-rulesets.md +++ b/docs/getting-started/3-rulesets.md @@ -29,6 +29,29 @@ Rules then target certain chunks of the JSON/YAML with the `given` keyword, whic The example above adds a single rule that looks at the root level `tags` object's children to make sure they all have a `description` property. +### JSONPath Plus + +As mentioned, spectral is using JSONPath Plus which expands on the original JSONPath specification to add some additional operators and makes explicit some behaviors the original did not spell out. + +Here are some convenient **additions or elaborations**: + +- `^` for grabbing the **parent** of a matching item +- `~` for grabbing **property names** of matching items (as array) +- **Type selectors** for obtaining: + - Basic JSON types: `@null()`, `@boolean()`, `@number()`, `@string()`, `@array()`, `@object()` + - `@integer()` + - The compound type `@scalar()` (which also accepts `undefined` and + non-finite numbers when querying JavaScript objects as well as all of the basic non-object/non-function types) + - `@other()` usable in conjunction with a user-defined `otherTypeCallback` + - Non-JSON types that can nevertheless be used when querying + non-JSON JavaScript objects (`@undefined()`, `@function()`, `@nonFinite()`) +- `@path`/`@parent`/`@property`/`@parentProperty`/`@root` **shorthand selectors** within filters +- **Escaping** + - `` ` `` for escaping remaining sequence + - `@['...']`/`?@['...']` syntax for escaping special characters within + property names in filters +- Documents `$..` (**getting all parent components**) + ### Extending Rulesets Rulesets can extend other rulesets using the `extends` property, allowing you to pull in other rulesets.