> For the complete documentation index, see [llms.txt](https://docs.kognitos.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kognitos.com/legacy/legacy-experience/automation-areas/summary-1/to-open-a-json-at-a-file/to-get-a-string-as-a-json.md).

# Get a String as a JSON

## Overview

This procedure converts a string to a JSON object by parsing the string content. The string should contain valid JSON syntax. The procedure automatically handles strings that may have extra text before or after the JSON content by identifying and extracting the JSON portion (looking for opening `{` or `[` and corresponding closing `}` or `]`).

## Input Concepts

| Concept | Type   | Description                                   | Required | Default |
| ------- | ------ | --------------------------------------------- | -------- | ------- |
| string  | string | The string to be converted into a JSON object | Yes      | N/A     |

## Output Concepts

| Concept | Description                                         |
| ------- | --------------------------------------------------- |
| json    | The JSON object obtained from the string conversion |

## Examples

### 1. Converting a simple JSON string

This example converts a string containing JSON to a JSON object.

```kog
get the string
get the string as json
```

### 2. Converting a string with JSON object

This example converts a string representation of a JSON object to an actual JSON object.

```kog
the string is '{"name":"John", "age":30, "city":"New York"}'
get the string as json
```

### 3. Converting and accessing JSON fields

This example shows converting a JSON string and then accessing its fields. The result would be "0.5% 10 NET 45" for Description and "38" for TermsCode.

```kog
the term is "{\"TermsCode\": \"38\", \"Description\": \"0.5% 10 NET 45\"}"
get the term as a json
get the json's Description
get the json's TermsCode
```

### 4. Converting a JSON array string

This example demonstrates converting a string containing a JSON array to an actual JSON array with multiple product objects.

```kog
the term is "[{\"Product Name\": \"P854282R COMP\", \"Quantity\": \"3\", \"Price\": \"$53.00\", \"Prices\": [\"1\", \"2\"]},{\"Product Name\": \"F854734 COMPR\", \"Quantity\": \"1\", \"Price\": \"$34.95\", \"Prices\": [\"2\", \"3\"]}]"
get the term as a json
```

### 5. Converting complex nested JSON

This example shows converting a complex nested JSON structure from a string and then accessing a field. For a JSON with nested objects like `{"u_project_name": {"link": "...", "value": "..."}, "state": "4"}`, this would return "4".

```kog
get the val as a json
get the json's state
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.kognitos.com/legacy/legacy-experience/automation-areas/summary-1/to-open-a-json-at-a-file/to-get-a-string-as-a-json.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
