# string

## String Methods

<details>

<summary><code>toAST(filepath=[string], returnType=[string], sourceType=[string])</code></summary>

Generates the Abstract Syntax Tree (AST) for BoxLang source code or a file.

The AST represents the syntactic structure of the code and can be used for code analysis, transformation, or generation.

,

, ,**,Usage Examples:,**, ,

,

,

```
,
// Parse source code and return as struct (default)
ast = boxAST( source = "x = 1 + 2" );
println( ast.ASTType ); // Outputs: BoxAssignment
// Parse source code and return as JSON
json = boxAST( source = "function add(a, b) { return a + b; }", returnType = "json" );
println( json ); // Outputs: JSON representation of the AST
// Parse source code and return as text
text = boxAST( source = "if (x > 5) { println('yes'); }", returnType = "text" );
println( text ); // Outputs: Human-readable text representation
// Parse a file
ast = boxAST( filepath = "src/MyClass.bx" );
// Use as a member function on a string
source = "a = [1, 2, 3]";
ast = source.toAST(); // Returns AST as struct
ast = source.toAST( returnType = "json" ); // Returns AST as JSON string
// Parse CFML/ColdFusion syntax
ast = boxAST( source = "cfset x = 1", sourceType = "cfscript" );
// Parse template syntax
ast = boxAST( source = ",<,bx:output>#now()#,<,/bx:output>", sourceType = "template" );
,
```

,

,

, The returned AST structure contains nodes with the following key properties: ,

, ,

* , ,
* ,**,ASTType,**, - The type of AST node (e.g., BoxAssignment, BoxFunctionDeclaration, BoxClass),
* , ,
* ,**,ASTPackage,**, - The package name of the AST node class,
* , ,
* ,Additional properties specific to each node type (e.g., name, value, children, etc.),
* , ,

Arguments:

| Argument     | Type     | Required | Default  |
| ------------ | -------- | -------- | -------- |
| `filepath`   | `string` | `false`  | `null`   |
| `returnType` | `string` | `false`  | `struct` |
| `sourceType` | `string` | `false`  | `script` |

</details>

<details>

<summary><code>jSONDeserialize(strictMapping=[boolean], useCustomSerializer=[string])</code></summary>

Converts a JSON (JavaScript Object Notation) string data representation into data, such as a structure or array.

Arguments:

| Argument              | Type      | Required | Default |
| --------------------- | --------- | -------- | ------- |
| `strictMapping`       | `boolean` | `false`  | `true`  |
| `useCustomSerializer` | `string`  | `false`  | `null`  |

</details>

<details>

<summary><code>fromJSON(strictMapping=[boolean], useCustomSerializer=[string])</code></summary>

Converts a JSON (JavaScript Object Notation) string data representation into data, such as a structure or array.

Arguments:

| Argument              | Type      | Required | Default |
| --------------------- | --------- | -------- | ------- |
| `strictMapping`       | `boolean` | `false`  | `true`  |
| `useCustomSerializer` | `string`  | `false`  | `null`  |

</details>

## Examples


---

# 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://boxlang.ortusbooks.com/boxlang-language/reference/types/string.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.
