# Json

This part provides json-related controller extensions and actions results.

## JsonResponse

`JsonResponse` class represents a result containing data object, errors list, message and success marker. It has following properties:

| Property name | Property type                                          | Description                                                                                                                     |
| ------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| Ok            | `bool`                                                 | `true` when there are no errors in result, otherwise `false`.                                                                   |
| Message       | `string`                                               | A message supplementing the result. Contains text of specified message or first error's message or `null` in case of no errors. |
| Data          | `object`                                               | A data attached to result;                                                                                                      |
| Errors        | [`IEnumerable<JsonResponseError>`](#jsonresponseerror) | A list of errors contained in result;                                                                                           |

The class has different constructors allowing to specify this properties in different combinations.

Working with class is performed by using controller extension [methods](#javascriptcontroller-extensions) that wrap instances of `JsonResponse` with `JsonResult`.

### JsonResponseError

This class represents an error to be transferred to a client.

| Property name | Property type | Description                        |
| ------------- | ------------- | ---------------------------------- |
| Key           | `string`      | Key corresponding to an error.     |
| Message       | `string`      | Message corresponding to an error. |

## JavaScriptController extensions

These extension methods provide possibilities of sending `JsonResponse` wrapped in `JsonResult`:

| Method name  | Return type    | Description                                                                      |
| ------------ | -------------- | -------------------------------------------------------------------------------- |
| JsonResponse | `JsonResponse` | Creates a `JsonResult` object, with serialized success marker, message and data. |

There are several overloads of this method taking as parameters the success marker, message, errors list and data.


---

# 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.structr.dev/presentation/aspnetcore/json.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.
