---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.4
alternate:
  - https://ydb.tech/docs/en/yql/reference/recipes/modifying-json.md
  - https://ydb.tech/docs/ru/yql/reference/recipes/modifying-json.md
sourcePath: en/core/yql/reference/recipes/modifying-json.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# Modifying JSON with YQL

In memory, YQL operates on immutable values. Thus, when a query needs to change something inside a JSON value, the mindset should be about constructing a new value from pieces of the old one.

This example query takes an input JSON named `$fields`, parses it, substitutes key `a` with 0, drops key `d`, and adds a key `c` with value 3:

```yql
$fields = '{"a": 1, "b": 2, "d": 4}'j;
$pairs = DictItems(Yson::ConvertToInt64Dict($fields));
$result_pairs = ListExtend(ListNotNull(ListMap($pairs, ($item) -> {
    $item = if ($item.0 == "a", ("a", 0), $item);
    return if ($item.0 == "d", null, $item);
})), [("c", 3)]);
$result_dict = ToDict($result_pairs);
SELECT Yson::SerializeJson(Yson::From($result_dict));
```

## See also

- [Yson](https://ydb.tech/docs/en/yql/reference/udf/list/yson.md)
- [Functions for lists](https://ydb.tech/docs/en/yql/reference/builtins/list.md)
- [Functions for dictionaries](https://ydb.tech/docs/en/yql/reference/builtins/dict.md)
- [Accessing values inside JSON with YQL](https://ydb.tech/docs/en/yql/reference/recipes/accessing-json.md)
