﻿---
title: ES|QL JSON_STRING function
description: 
url: https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/query-languages/esql/functions-operators/string-functions/json_string
products:
  - Elasticsearch
---

# ES|QL JSON_STRING function
<applies-to>
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Planned
</applies-to>

Builds a JSON object string from key/value pairs.

## Syntax

![Embedded](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/query-languages/esql/images/generated/x-pack-esql/functions/json_string.svg)


## Parameters

<definitions>
  <definition term="key">
    The key of the first key/value pair.
  </definition>
  <definition term="value">
    The value of the first pair, followed by any further alternating keys and values. Provide arguments as alternating key/value pairs.
  </definition>
</definitions>


## Description

Builds a JSON object string from one or more key/value pairs. Keys must be strings. Numbers and booleans are rendered as JSON primitives, all other values are rendered as JSON strings. A multi-valued value is rendered as a JSON array and a null value as JSON `null`.

## Supported types


| key     | value         | result  |
|---------|---------------|---------|
| keyword | boolean       | keyword |
| keyword | date          | keyword |
| keyword | date_nanos    | keyword |
| keyword | double        | keyword |
| keyword | integer       | keyword |
| keyword | ip            | keyword |
| keyword | keyword       | keyword |
| keyword | long          | keyword |
| keyword | text          | keyword |
| keyword | unsigned_long | keyword |
| keyword | version       | keyword |
| text    | boolean       | keyword |
| text    | date          | keyword |
| text    | date_nanos    | keyword |
| text    | double        | keyword |
| text    | integer       | keyword |
| text    | ip            | keyword |
| text    | keyword       | keyword |
| text    | long          | keyword |
| text    | text          | keyword |
| text    | unsigned_long | keyword |
| text    | version       | keyword |


## Example

```esql
ROW name = "Sydney", population = 5312163
| EVAL doc = JSON_STRING("city", name, "population", population)
```


| doc:keyword                            |
|----------------------------------------|
| {"city":"Sydney","population":5312163} |