# Easiest way of replacing a item in JSON

**URL:** <https://discourse.nodered.org/t/easiest-way-of-replacing-a-item-in-json/35759>\
**Category:** General\
**Created:** [11 November 2020 19:02 UTC](https://discourse.nodered.org/t/easiest-way-of-replacing-a-item-in-json/35759 "2020-11-11T19:02:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![CrunkFX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crunkfx/32/30959_2.png) [@CrunkFX](https://discourse.nodered.org/u/CrunkFX)\
**Post date:** [11 November 2020 19:02 UTC](https://discourse.nodered.org/t/easiest-way-of-replacing-a-item-in-json/35759/1 "2020-11-11T19:02:46Z")

</div>

So, i got a JSON string like this:

```auto
{ "Attribute1":"Test","Value1":"Testvalue" }

```

It got like 20 Attributes with corresponding values. The String is being loaded and saved from and to a file, which isn´t a problem, but how can i easily change 1 Value in the existing String, coming from another source like MQTT.

I tried it using the change node and Flow messages, which works but i guess there might be a more efficient way to do that, maybe with a function node?

I´ll have to use this like a hundred times so it would be great to have only a few nodes to be configured.

Thanks in advance  
CrunkFX

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 November 2020 21:07 UTC](https://discourse.nodered.org/t/easiest-way-of-replacing-a-item-in-json/35759/2 "2020-11-11T21:07:26Z")

</div>

First convert it from a string to a javascript object using a JSON node (or if it is coming from MQTT then configure the MQTT node to output a Parsed JSON object, so it will parse the JSON and convert to an onbject.  
Then you can join that message with the other MQTT message using the pattern in the [Joining Streams](https://cookbook.nodered.org/basic/join-streams) example in the cookbook. That will give you both payloads in one message so you can combine them as appropriate.  
However, if you have to do this 100 times I wonder whether there may be a better way of organising it. Perhaps if you explained the broader problem you are trying to solve someone may come up with a better solution.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [11 November 2020 21:20 UTC](https://discourse.nodered.org/t/easiest-way-of-replacing-a-item-in-json/35759/3 "2020-11-11T21:20:37Z")

</div>

In fact you may be able to use the Merged Object mode of the Join Node. It depends on the detail of what you want to do.

---

<div class="post-metadata">

**Author:** ![CrunkFX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crunkfx/32/30959_2.png) [@CrunkFX](https://discourse.nodered.org/u/CrunkFX)\
**Post date:** [12 November 2020 10:50 UTC](https://discourse.nodered.org/t/easiest-way-of-replacing-a-item-in-json/35759/4 "2020-11-12T10:50:07Z")

</div>

I'll give this a try later thanks. Then I'll be able to come up with a better way of designing the Sender.

---

<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:** [11 January 2021 10:50 UTC](https://discourse.nodered.org/t/easiest-way-of-replacing-a-item-in-json/35759/5 "2021-01-11T10:50:26Z")

</div>

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