# JsonList parser

**URL:** <https://community.graylog.org/t/jsonlist-parser/23987>\
**Category:** Graylog Central (peer support)\
**Tags:** pipeline-rules\
**Created:** [May 24, 2022, 4:40pm UTC](https://community.graylog.org/t/jsonlist-parser/23987 "2022-05-24T16:40:10Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [May 24, 2022, 4:40pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/1 "2022-05-24T16:40:10Z")

</div>

Hi,  
is there a function that I can use in Graylog when a json key has a complex value, like a list of element?  
I mean, if I have a json like:  
`{"DeviceProperties":{Name=OS, Value=MacOs}, {Name=BrowserType, Value=Chrome}}`

is there something that can be used to map all of that list values?  
For example  
DeviceProperties\_OS = MacOs and so on

Thanks  
Gianluca

---

<div class="post-metadata">

**Author:** ![tmacgbay](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/tmacgbay/32/3878_2.png) [@tmacgbay](https://community.graylog.org/u/tmacgbay)\
**Post date:** [May 24, 2022, 7:11pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/2 "2022-05-24T19:11:34Z")

</div>

I think there is a JSON extractor, there is also parse\_json() in the pipeline that you can follow with a set\_fields() there were some other posts around here with people using them…

---

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [May 25, 2022, 3:25pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/3 "2022-05-25T15:25:42Z")

</div>

Hi, I used the json Extractor but the result, for list object is not a valid json

 ![image](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/2X/7/7d772ea76c43f99c8994f51957304571ff432914.png)

It seems to be the java HashMap.toString method output instead.  
With this output I cannot work with it as a json

---

<div class="post-metadata">

**Author:** ![tmacgbay](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/tmacgbay/32/3878_2.png) [@tmacgbay](https://community.graylog.org/u/tmacgbay)\
**Post date:** [May 25, 2022, 4:28pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/4 "2022-05-25T16:28:23Z")

</div>

> [@gianluca-valentini](#):
>
> {“DeviceProperties”:{Name=OS, Value=MacOs}, {Name=BrowserType, Value=Chrome}}

This isn’t a valid json either… 😛

It’s hard to work with text from a screen shot, use the \</\> forum tool and paste in actual text. What does the original message look like? I don’t have enough information to make suggestions…

---

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [May 25, 2022, 5:14pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/5 "2022-05-25T17:14:44Z")

</div>

> [@gianluca-valentini](#):
>
> {“DeviceProperties”:{Name=OS, Value=MacOs}, {Name=BrowserType, Value=Chrome}}

You are right.  
The original field contains the correct json text (before json exractor)

`{"DeviceProperties":[{"Name":"OS","Value":"MacOs"},{"Name":"BrowserType","Value":"Chrome"},{"Name":"IsCompliantAndManaged","Value":"False"},{"Name":"SessionId","Value":"dc4fe5cd-6bbf-4968-946a-51b5e7c4f872"}]}`

consider that between the Name and OS I have the correct colons separator key.

After JSon extractor I have the result that I attached in the previous message where  
DeviceProperties is the key and the value is a string that I post before that seems a Map.toString output.  
As you can see , the quotes are missing too. So I think that the jsonExctractor fails the json parse the the field is an object

---

<div class="post-metadata">

**Author:** ![tmacgbay](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/tmacgbay/32/3878_2.png) [@tmacgbay](https://community.graylog.org/u/tmacgbay)\
**Post date:** [May 25, 2022, 6:21pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/6 "2022-05-25T18:21:55Z")

</div>

Hmmm… I did a little searching -[this post here](https://community.graylog.org/t/failing-json-extractor/7944) goes into more depth about json… it may help to find what you need…

---

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [May 27, 2022, 10:42am UTC](https://community.graylog.org/t/jsonlist-parser/23987/7 "2022-05-27T10:42:19Z")

</div>

Thanks a lot for your help

---

<div class="post-metadata">

**Author:** ![tmacgbay](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/tmacgbay/32/3878_2.png) [@tmacgbay](https://community.graylog.org/u/tmacgbay)\
**Post date:** [May 27, 2022, 2:46pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/8 "2022-05-27T14:46:30Z")

</div>

If you find a solution in there - post it up for future searchers - otherwise continue to ask, we’ll figure it out together!

---

<div class="post-metadata">

**Author:** ![patrickmann](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/patrickmann/32/9091_2.png) [@patrickmann](https://community.graylog.org/u/patrickmann)\
**Post date:** [May 30, 2022, 8:02am UTC](https://community.graylog.org/t/jsonlist-parser/23987/9 "2022-05-30T08:02:05Z")

</div>

Try the `flatten_json` function with parameter `array_handler` = “flatten”  
[https://docs.graylog.org/docs/functions-1#flatten\_json](https://docs.graylog.org/docs/functions-1#flatten_json)

---

<div class="post-metadata">

**Author:** ![gianluca-valentini](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gianluca-valentini/32/1592_2.png) [@gianluca-valentini](https://community.graylog.org/u/gianluca-valentini)\
**Post date:** [May 30, 2022, 9:58am UTC](https://community.graylog.org/t/jsonlist-parser/23987/10 "2022-05-30T09:58:15Z")

</div>

Hi @tmacgbay  
i solved creating my own function after remove double quote and using

```auto
let json_tree = parse_json(to_string($message."message_unquote"));
let jsonNode = to_map(json_tree);

```

my function is named **list\_fieldKVMap** where

 ![image](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/2X/8/85366efc1e8b7e2d95136922e7516271dbf45702.png)

for example:

> list\_fieldKVMap(“DeviceProperties”, jsonNode[“DeviceProperties”], “Name”, “Value”);

So, inside I get the object list and extract the field/value attribute. I add a new field using the parameterKey as key prefix

Remembering the input data:

> {“ **DeviceProperties** ”:[{“Name”:“OS”,“Value”:“MacOs”},{“Name”:“BrowserType”,“Value”:“Chrome”},{“Name”:“IsCompliantAndManaged”,“Value”:“False”},{“Name”:“SessionId”,“Value”:“dc4fe5cd-6bbf-4968-946a-51b5e7c4f872”}]}

the output is something like this:  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/2X/a/a82859fc51977a9e6e5683994f6c9c9fa503fd05.png)

With this approach I can reuse this function for other object list changing the attributes that I have to use for new field generation

Gianluca

---

<div class="post-metadata">

**Author:** ![tmacgbay](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/tmacgbay/32/3878_2.png) [@tmacgbay](https://community.graylog.org/u/tmacgbay)\
**Post date:** [May 31, 2022, 8:06pm UTC](https://community.graylog.org/t/jsonlist-parser/23987/11 "2022-05-31T20:06:21Z")

</div>

Great! It would be interesting to have a write up on how to create your own function and put it in the “templates and rules exchange” section. 😃

---

<div class="post-metadata">

**Author:** ![gsmith](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gsmith/32/1222_2.png) [@gsmith](https://community.graylog.org/u/gsmith)\
**Post date:** [June 1, 2022, 1:32am UTC](https://community.graylog.org/t/jsonlist-parser/23987/12 "2022-06-01T01:32:43Z")

</div>

I second that what @tmacgbay stated

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/3X/c/7/c7c09c6b5099570133d6502b83f50ba4430de5b6.png) [@system](https://community.graylog.org/u/system)\
**Post date:** [June 15, 2022, 1:33am UTC](https://community.graylog.org/t/jsonlist-parser/23987/13 "2022-06-15T01:33:09Z")

</div>

Closed on June 15, 2022, 1:33am UTC

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