# Send error status message that arrives as malfromed JSON String

**URL:** <https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801>\
**Category:** General\
**Created:** [6 February 2023 16:04 UTC](https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801 "2023-02-06T16:04:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SurfingSpider](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/surfingspider/32/71202_2.png) [@SurfingSpider](https://discourse.nodered.org/u/SurfingSpider)\
**Post date:** [6 February 2023 16:04 UTC](https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801/1 "2023-02-06T16:04:31Z")

</div>

I have my 3d printer connected to Home assistant which I use Node Red to do some automations.

I am trying to send a message with the status information from moonraker (Klipper firmware) when there is an error.

I can get the error message in Node red but am having trouble using it. At first glance it looks like JSON but has errors when I parse it.

The Status message is ....

> {"code":"key244": "msg":"Extrude only move too long (-3912.506mm vs 2000.000mm)  
> See the 'max\_extrude\_only\_distance' config option for details", "values":[-3912.506, 2000.000]}

If I send this to a Home Assistant Call Service (Notification) as the Message. I get an error

> Call-service error. extra keys not allowed @ data['0']

Ideally I would like to strip the value of message out of this (Extrude only move too long (-3912.506mm vs 2000.000mm) See the 'max\_extrude\_only\_distance' config option for details)

But if I pass the message to a JSON node I get ..

> Unexpected token : in JSON at position 16

Any ideas how I can work with this status message? to send it out as a string?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 February 2023 16:16 UTC](https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801/2 "2023-02-06T16:16:42Z")

</div>

> [@SurfingSpider](#):
>
> {"code":"key244": "msg":"Extrude only move too long (-3912.506mm vs 2000.000mm)  
> See the 'max\_extrude\_only\_distance' config option for details", "values":[-3912.506, 2000.000]}

There are two problems with that msg (1) the `:` between `key244` and `msg` should be a comma.  
(2) there is a unescaped new line character in the long string

---

<div class="post-metadata">

**Author:** ![SurfingSpider](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/surfingspider/32/71202_2.png) [@SurfingSpider](https://discourse.nodered.org/u/SurfingSpider)\
**Post date:** [6 February 2023 16:41 UTC](https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801/3 "2023-02-06T16:41:55Z")

</div>

Thank you for your response. I do appreciate your help.

The problem is I did not create the message. I only receive it from my 3d printer software. So I cant correct it.

I would just like to send it as a text string to a mobile phone notification. So I know why the print has failed.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 February 2023 16:47 UTC](https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801/4 "2023-02-06T16:47:49Z")

</div>

You should report it to whom ever created the software, maybe they can fix it and publish a new release

Do you receive other messages or just this one?

In the meantime you could use a `change` node to fix the string. Here is an example using that data (it's in the inject node)

```auto
[{"id":"4fd59efb2f3759cb","type":"inject","z":"58d202c52925b8cb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"code\":\"key244\": \"msg\":\"Extrude only move too long (-3912.506mm vs 2000.000mm) See the 'max_extrude_only_distance' config option for details\", \"values\":[-3912.506, 2000.000]}","payloadType":"str","x":130,"y":100,"wires":[["f983334c92632273"]]},{"id":"f983334c92632273","type":"change","z":"58d202c52925b8cb","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"\": \"msg","fromt":"str","to":"\", \"msg","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"\\n","fromt":"str","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":160,"wires":[["f49328d84bad9d6d"]]},{"id":"273372bf19b7ccda","type":"debug","z":"58d202c52925b8cb","name":"debug 43","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":140,"y":280,"wires":[]},{"id":"f49328d84bad9d6d","type":"json","z":"58d202c52925b8cb","name":"","property":"payload","action":"","pretty":false,"x":150,"y":220,"wires":[["273372bf19b7ccda"]]}]

```

---

<div class="post-metadata">

**Author:** ![SurfingSpider](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/surfingspider/32/71202_2.png) [@SurfingSpider](https://discourse.nodered.org/u/SurfingSpider)\
**Post date:** [6 February 2023 21:47 UTC](https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801/5 "2023-02-06T21:47:35Z")

</div>

Thank you again for your response. I think found in the HA integration it was going wrong. I have found an alternative version that seams to produce valid JSON now. I will use that

Chris

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 April 2023 21:48 UTC](https://discourse.nodered.org/t/send-error-status-message-that-arrives-as-malfromed-json-string/74801/6 "2023-04-07T21:48:31Z")

</div>

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