# Modify JSON property to include additional text -maybe using regex?

**URL:** <https://discourse.nodered.org/t/modify-json-property-to-include-additional-text-maybe-using-regex/59822>\
**Category:** General\
**Created:** [14 March 2022 01:53 UTC](https://discourse.nodered.org/t/modify-json-property-to-include-additional-text-maybe-using-regex/59822 "2022-03-14T01:53:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anakaine](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anakaine](https://discourse.nodered.org/u/anakaine)\
**Post date:** [14 March 2022 01:53 UTC](https://discourse.nodered.org/t/modify-json-property-to-include-additional-text-maybe-using-regex/59822/1 "2022-03-14T01:53:44Z")

</div>

I have some JSON that looks like the following:

```auto
{
        "StationNum": 32109,
        "Height": 3.686
    },
    {
        "StationNum": 32152,
        "Height": 1.598
    },
    {
        "StationNum": 32155,
        "Height": 1.768
    },
    {
        "StationNum": 32167,
        "Height": 3.527
    }

```

Is there a way to use the StationNum with something like regex and change it to be more like the following. Note that I've added text either side of the number:

```auto
{
        "StationNum": "G_32109_Height",
        "Height": 3.686
    },
    {
        "StationNum": "G_32152_Height",
        "Height": 1.598
    },
    {
        "StationNum": "G_32155_Height",
        "Height": 1.768
    },
    {
        "StationNum": "G_32167_Height",
        "Height": 3.527
    }

```

Regex for matching the StationNum is (I believe): `(\s[0-9]{5,7})+`. What I'm stuck with, is if I can use this in a replace.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [14 March 2022 03:11 UTC](https://discourse.nodered.org/t/modify-json-property-to-include-additional-text-maybe-using-regex/59822/2 "2022-03-14T03:11:17Z")

</div>

Your object is not valid is it supposed to be an array of objects.  
If so the expresion to transfrom the stationNum would be

```auto
$$.payload ~> |$|{"StationNum": "G_" & StationNum & "_Height"}|

```

Input

```auto
   [
        {
            "StationNum": 32109,
            "Height": 3.686
        },
        {
            "StationNum": 32152,
            "Height": 1.598
        },
        {
            "StationNum": 32155,
            "Height": 1.768
        },
        {
            "StationNum": 32167,
            "Height": 3.527
        }
    ]

```

Output

```auto
[
    {
        "StationNum": "G_32109_Height",
        "Height": 3.686
    },
    {
        "StationNum": "G_32152_Height",
        "Height": 1.598
    },
    {
        "StationNum": "G_32155_Height",
        "Height": 1.768
    },
    {
        "StationNum": "G_32167_Height",
        "Height": 3.527
    }
]

```

---

<div class="post-metadata">

**Author:** ![anakaine](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anakaine](https://discourse.nodered.org/u/anakaine)\
**Post date:** [14 March 2022 04:03 UTC](https://discourse.nodered.org/t/modify-json-property-to-include-additional-text-maybe-using-regex/59822/3 "2022-03-14T04:03:16Z")

</div>

Thank you very much!

---

<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:** [13 May 2022 04:04 UTC](https://discourse.nodered.org/t/modify-json-property-to-include-additional-text-maybe-using-regex/59822/4 "2022-05-13T04:04:12Z")

</div>

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