PingAccess

JsonNode object reference

The JsonNode object represents the attributes of an identity.

Groovy sample

// Only allow access if the user is in the group "staff"
def groups = exc?.identity?.attributes?.get("groups")

foundGroup = falseif (groups) {
  for (group in groups) {
    if ("staff".equals(group.asText())) {
      foundGroup = truebreak
    }
  }
}

if (foundGroup) {
  pass()
} else {
  fail()
}

Method summary

Method Description

JsonNode get(String fieldName)

Gets the JsonNode representing a field of this JsonNode. This method will return null if no field exists with the specified name.

boolean has(String fieldName)

Returns true if this JsonNode has a field with the specified name.

java.util.IteratorString fieldNames()

Returns an java.util.Iterator providing access to the names of all the fields of this JsonNode.

boolean isTextual()

Returns true if this JsonNode represents a string value.

String asText()

Returns a string representation of this JsonNode. If this JsonNode is an array or object, this will return an empty string.

int intValue()

Returns an integer representation of this JsonNode. If this JsonNode does not represent a number, 0 is returned.

boolean isArray()

Returns true if this JsonNode is an array.

boolean isObject()

Returns true if this JsonNode is an object.

int size()

For an array JsonNode, returns the number of elements in the array. For an object JsonNode, returns the number of fields in the object. 0 otherwise.

java.util.IteratorJsonNodeiterator()

Returns an java.util.Iterator over all JsonNode objects contained in this JsonNode. For an array JsonNode, the returned java.util.Iterator will iterate over all the elements in the array. For an object JsonNode, the returned java.util.Iterator will iterate over all field values in the object.

Remarks

A JsonNode implements java.lang.IterableJsonNode so a for loop can be used to iterate over all the elements in an array JsonNode or the field values in an object JsonNode.