diff --git a/docs/scenarios_authoring/Spel.md b/docs/scenarios_authoring/Spel.md index 471cd758c3a..2069fa06860 100644 --- a/docs/scenarios_authoring/Spel.md +++ b/docs/scenarios_authoring/Spel.md @@ -238,6 +238,34 @@ If you need to invoke the same method in many places, probably the best solution | ------------ | -------- | -------- | | `{1, 2, 3, 4}.?[#this > 1].![#this > 2 ? #this * 2 : #this]` | {2, 6, 8} | Double | +### Dynamic navigation + +When we deal with structures which schema is not known to Nussknacker (e.g. data from kafka topics without existing avro/json schema) we will end-up +with `Unknown` type in designer. For such a type (`Unknown`) we allow dynamic-like access using `[]` operator to access nested fields/elements. + +Example `exampleObject` json-like variable +``` +{ + "someField": 123, + "someNestedObject": { + "someFieldInNestedObject": "value" + } + "someArrayWithObjects": [ + { + "someFieldInObjectInArray": "value" + } + ] +} +``` + +can be accessed in e.g. in following ways: + +* `#exampleObjects['someField']` +* `#exampleObjects['someNestedObject']['someFieldInNestedObject']` +* `#exampleObjects['someArrayWithObjects'][0]['someFieldInObjectInArray']` + +Every unknown accessed field/element will produce `Unknown` data type which can be further navigated or [cast](#Casting) to a desired type. + ### Type conversions It is possible to convert from a type to another type and this can be done by implicit and explicit conversion. @@ -299,35 +327,6 @@ Available methods: - `castToOrNull` - casts a type to a given class or return null if type cannot be cast. -## Dynamic navigation - -When we deal with structures which schema is not known to Nussknacker (e.g. data from kafka topics without existing avro/json schema) we will end-up -with `Unknown` type in designer. For such a type (`Unknown`) we allow dynamic-like access using `[]` operator to access nested fields/elements. - -Example `exampleObject` json-like variable -``` -{ - "someField": 123, - "someNestedObject": { - "someFieldInNestedObject": "value" - } - "someArrayWithObjects": [ - { - "someFieldInObjectInArray": "value" - } - ] -} -``` - -can be accessed in e.g. in following ways: - -* `#exampleObjects['someField']` -* `#exampleObjects['someNestedObject']['someFieldInNestedObject']` -* `#exampleObjects['someArrayWithObjects'][0]['someFieldInObjectInArray']` - -Every unknown accessed field/element will produce `Unknown` data type which can be further navigated or [cast](#Casting) to a desired type. - - ## Built-in helpers Nussknacker comes with the following helpers: