# JsonNode

The `JsonNode` class is a versatile class designed to work with JSON-like data structures. It provides a set of methods to navigate, manipulate, and extract information from JSON data. This class is particularly useful for handling and processing JSON data within your applications.

### Methods

* `get(property: String): JsonNode`:&#x20;

This method is used to retrieve a nested property (key) from the JSON-like data, returning a new `JsonNode` representing the specified property.

```typescript
// Assuming you have a JsonNode representing a JSON object
// Get a nested property from the JSON object
var nestedProperty = jsonObject.get("nestedProperty");
```

* `asText(): String`:&#x20;

It returns the content of the `JsonNode` as a string, assuming the content is textual.

```typescript
// Assuming you have a JsonNode containing a textual value
// Get the content of the JsonNode as a string
var textValue = textNode.asText();
```

* `asInt(): Integer`:&#x20;

This method converts the `JsonNode` to an integer value if it's numeric; otherwise, it may throw an error or return a default value.

```typescript
// Assuming you have a JsonNode containing a numeric value
// Get the JsonNode as an integer, handling non-numeric values
var intValue = numericNode.asInt();
```

* `asBoolean(): Boolean`:&#x20;

Converts the `JsonNode` to a Boolean value if it's a valid boolean value; otherwise, it may throw an error or return a default value.

```typescript
// Assuming you have a JsonNode containing a boolean value
// Get the JsonNode as a Boolean, handling non-boolean values
var boolValue = booleanNode.asBoolean(); // May throw an exception for non-boolean values
```

* `isObject(): Boolean`:&#x20;

Checks if the `JsonNode` represents a JSON object and returns `true` if it is an object, otherwise `false`.

```typescript
// Assuming you have a JsonNode
// Check if the JsonNode represents a JSON object
var isObject = jsonNode.isObject();
```

* `isArray(): Boolean`:&#x20;

Similar to `isObject`, this method checks if the `JsonNode` represents a JSON array and returns `true` if it is an array, otherwise `false`.

```typescript
// Assuming you have a JsonNode
// Check if the JsonNode represents a JSON array
var isArray = jsonNode.isArray();
```

* `isNumber(): Boolean`:&#x20;

Determines if the `JsonNode` represents a numeric value and returns `true` if it's numeric, otherwise `false`.

```typescript
// Assuming you have a JsonNode
// Check if the JsonNode represents a numeric value
var isNumber = jsonNode.isNumber();
```

* `isBoolean(): Boolean`:&#x20;

Checks if the `JsonNode` represents a Boolean value and returns `true` if it's a boolean, otherwise `false`.

```typescript
// Assuming you have a JsonNode
// Check if the JsonNode represents a Boolean value
var isBoolean = jsonNode.isBoolean();
```

* `isNull(): Boolean`:&#x20;

Checks if the `JsonNode` is null and returns `true` if it's null, otherwise `false`.

```typescript
// Assuming you have a JsonNode
// Check if the JsonNode is null
var isNull = jsonNode.isNull();
```

* `isTextual(): Boolean`:

Determines if the `JsonNode` contains textual data and returns `true` if it's textual, otherwise `false`.

```typescript
// Assuming you have a JsonNode containing textual data
// Check if the JsonNode contains textual data
var isTextual = textNode.isTextual();
```

* `toPrettyString(): String`:&#x20;

This method returns a nicely formatted, pretty-printed string representation of the JSON data contained in the `JsonNode`.

```typescript
// Assuming you have a JsonNode
// Get a pretty-printed string representation of the JSON data
var prettyJson = jsonNode.toPrettyString();
```

* `toString(): String`:&#x20;

Returns a string representation of the JSON data contained in the `JsonNode`.

```typescript
// Assuming you have a JsonNode
// Get a string representation of the JSON data
var jsonString = jsonNode.toString();
```

* `hasNonNull(filed: String): Boolean`:&#x20;

Checks if the `JsonNode` contains a non-null field with the specified name and returns `true` if it exists and is not null, otherwise `false`.

```typescript
// Assuming you have a JsonNode representing a JSON object
// Check if the JsonNode has a non-null field named "fieldName"
var hasField = jsonObject.hasNonNull("fieldName");
```

### Examples

**Example: JSON Property Retrieval**

```javascript
// Assuming you have a JSON object retrieved from Context.getCreatedBy()
var json = Context.getStartedBy(); // getStartedBY method of Context Class

// Get a specific property from the JSON object
var propertyNode = json.get("propertyName");
if (propertyNode != null) {
    var propertyValue = propertyNode.asText();
    return ("Value of 'propertyName': " + propertyValue);
} else {
    return ("The 'propertyName' property does not exist in the JSON object.");
}
```

To access additional JSON utility functions, please refer to [JsonUtil Class](/scripting/utilities/jsonutil.md) in [Utilities](/scripting/utilities.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.b2winsuite.com/scripting/types-and-objects/objects/jsonnode.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
