# Split json

**URL:** <https://discuss.elastic.co/t/split-json/224952>\
**Category:** Logstash\
**Created:** [March 25, 2020, 7:21am UTC](https://discuss.elastic.co/t/split-json/224952 "2020-03-25T07:21:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JPelastic](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@JPelastic](https://discuss.elastic.co/u/JPelastic)\
**Post date:** [March 25, 2020, 7:21am UTC](https://discuss.elastic.co/t/split-json/224952/1 "2020-03-25T07:21:18Z")

</div>

Problem is basic: I just don't understand how split/mutate works.  
I got nested json data from an elastic source that I want to flatten into a new elastic target (for context).

Data:

```auto
    ....
    "artikel" => {
          "gTIN" => "04011395096406",
          "artikelcodeLeverancier" => "0517797",
          "artikelcodeAfnemer" => ""
    },
    ....

```

and logstash .conf

```auto
json {
		source => "artikel"
	}
	split {
		field => "artikel"
	}
	mutate {
		add_field => {
			"gtin" => "%{artikel}"
		}
		remove_field => ["artikel"]
	}

```

Result looks like this (output to stdout). I believe the gtin field now contains json - how do I only get the gtin?

```auto
    ....
    "verzenderAdresStraat" => "Bovenkerkerweg 10-12",
    "gtin" => "{\"artikelcodeAfnemer\":\"\",\"artikelIdentificatie\":[{\"promotieVariantcode\":\"\",\"artikelomschrijving\":\"BJ WCD 1V RA 2300EAPJ MP AP\",\"nadereIdentificerendeKenmerken\":\"\",\"artikelStatistiekcode\":\"\"}],\"gTIN\":\"04011395090176\",\"artikelcodeLeverancier\":\"3926698\"}",
    "partijnummer" => "",
    ...
                        

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [March 25, 2020, 3:39pm UTC](https://discuss.elastic.co/t/split-json/224952/2 "2020-03-25T15:39:37Z")

</div>

The split filter can operate on an array or a string, and [artikel] is neither one. It should just log an error and not do anything.

To reference a field inside [artikel] you can use

```
mutate { add_field => { "gtin" => "%{[artikel][gTIN]}" } }
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 22, 2020, 3:39pm UTC](https://discuss.elastic.co/t/split-json/224952/3 "2020-04-22T15:39:44Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
