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

I have some JSON that looks like the following:

{
        "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:

{
        "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.

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

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

Input

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

Output

[
    {
        "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
    }
]

Thank you very much!

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