In this Page
...
Description | Find the value for the given property name. If the property does not exist, the function returns the default value (if given); otherwise, null is returned. If the value is a populated list, then the function returns the first value in the list; otherwise, it returns the default value if present or null. | |
---|---|---|
Syntax |
| |
Example | Expression: Where $test is the string "abc123" Result: abc123 Expression: Where $test is a list consisting of [5, 10, 15, 20] Result: 5 |
hasOwnProperty
Indicates whether the object has the specified property. This method is recommended when working with JSON-Path, especially when looking for fields nested deep within the object.
Info |
---|
This expression is useful since, if you use the hasOwnProperty method, you have to construct complex sub-expressions to check if the field exists. |
Paste code macro |
---|
object.hasPath(field) |
Expression: $.hasPath("Id")
Description | Indicates whether Returns a boolean value to indicate whether the object has the specified property. The in operator and get method can be used as a shorthand to test if an object has a property or get the value of a property with a default if it does not exist.
| ||
---|---|---|---|
Syntax |
| ||
Example | Expression: Result: Returns true if the object has the key "Id" Expression: To create a ternary conditional expression:
|
hasPath
. Expression: Result:
Expression: To create a ternary conditional expression:
|
hasPath
Description | Returns a boolean value to indicate whether the object has the specified property (path) that carries a non-null value. This method is recommended when working with JSONPath, especially when looking for fields nested deep within the object.
| |||||||||
---|---|---|---|---|---|---|---|---|---|---|
Syntax |
| |||||||||
Example | Expression: Result: Returns true. Expression: Result:
Example JSON Object:
Expression: Result: Returns true because the object "Type" has a specified value. Expression:
Result: Returns true because "EditorName" has a specified value. Expression: Result: Returns false since even though the object has the key "Owner", it is null. Expression: Result: Returns false since the object does not have "Region". |
isEmpty
Description | Returns true if the given object has no properties.
| ||
---|---|---|---|
Syntax |
| ||
Example | Expression: {}.isEmpty() Result: Returns true. Expression: { foo: 1 }.isEmpty() Result: Returns false. |
...
Description | Returns an array containing the given object's own enumerable property values. See also entries, keys. | ||
---|---|---|---|
Syntax |
| ||
Example | Input: Code Block |
age
Expression: $user.values() |
...
Expand | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||
A JSON Array of objects with unique/non-overlapping keys can be converted to an object using the extend object method along with a Spread Operator. The extend object method does so by creating objects dynamically from other objects passed in as arguments, the spread operator will have to be used to indicate that the elements of the array should be treated as the arguments to the function. The expression to be used is:
1. Input the array into Mapper Snap (this can be done using a JSON Generator Snap). For this example, the following array will be used:
2. The Mapper Snap must be configured as shown below. Notice the Expression and Target path fields.3. When executed, the output will be an object.
|