# Graylog pipeline: handling null values

**URL:** <https://community.graylog.org/t/graylog-pipeline-handling-null-values/31781>\
**Category:** Graylog Central (peer support)\
**Tags:** pipeline-rules, key\_value\
**Created:** [March 11, 2024, 2:29pm UTC](https://community.graylog.org/t/graylog-pipeline-handling-null-values/31781 "2024-03-11T14:29:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgrammen\_agility](https://avatars.discourse-cdn.com/v4/letter/j/7993a0/32.png) [@jgrammen\_agility](https://community.graylog.org/u/jgrammen_agility)\
**Post date:** [March 11, 2024, 2:29pm UTC](https://community.graylog.org/t/graylog-pipeline-handling-null-values/31781/1 "2024-03-11T14:29:21Z")

</div>

Before you post: Your responses to these questions will help the community help you. Please complete this template if you’re asking a support question.  
**Don’t forget to select tags to help index your topic!**

**1. Describe your incident:**  
I have a graylog pipeline rule that extracts a bunch of fields from a json message body

```auto
rule "message_json_tofields"
when
  has_field("message")
then
    let json_from_message = regex("^.*]: (.*)",to_string($message.message))["0"];
    let json = parse_json(to_string(json_from_message));
    let props = select_jsonpath(json, {client_ip: "$.client_ip"});
   // repeat for a number of fields
  // field i have having issue with
    set_fields(to_map(props));
let props = select_jsonpath(json, {request_headers_cookie: "$.request.headers.cookie"});
    let api_key = key_value(to_string(props["request_headers_cookie"]),";","=");
    set_fields(to_map({request_headers_cookie_apiKey:api_key["apiKey"]}));
    

```

I am having trouble with the cookie field. I can exact from the json no problem. spliting the string into key\_value pairs ended up being easy via key\_value. But the crux of my issue is that the field key `apiKey`, may or may not exist within `cookie`.  
When it doesnt exist the whole pipeline errors

```auto
(Error: In call to function 'to_map' at 47:15 an exception was thrown: null)

```

is there any graceful way to handle the field some times being null?

**2. Describe your environment:**

- OS Information: ubuntu 22.04

- Package Version:  
5.2.5-1

- Service logs, configurations, and environment variables:

**3. What steps have you already taken to try and solve the problem?**  
tried a bunch of ways to extract the value, but pipeline still errors due to null value

**4. How can the community help?**  
any helpful hints/ideas about graylog pipeline processing

---

<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:** [March 25, 2024, 2:29pm UTC](https://community.graylog.org/t/graylog-pipeline-handling-null-values/31781/2 "2024-03-25T14:29:39Z")

</div>

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