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

# Modifying JSON with YQL

In memory, YQL works with immutable values. When a query needs to change something inside a JSON value, think of it as constructing a new value from parts of the old one.

This sample query takes an input JSON named `$fields`, parses it, substitutes the `a` key with 0, deletes the `d` key, and adds the `c` key 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://ytsaurus.tech/docs/en/yql/udf/list/yson.md)
- [Functions for lists](https://ytsaurus.tech/docs/en/yql/builtins/list.md)
- [Functions for working with dicts](https://ytsaurus.tech/docs/en/yql/builtins/dict.md)
- [Accessing values inside JSON with YQL](https://ytsaurus.tech/docs/en/yql/recipes/accessing-json.md)
