Best way to parse a string into an array

Hi community

So…i have a module which provides a string like this (From the output bundle)

[
    {
        "body": {
            "statusCode": 200,
            "body": "User: john.smith@email.com, Show 1 Delegate Delegate: jane.doe@email.com Status: accepted"
        }
    }
]

I am wanting to convert this output into fields i can select (e.g possibly into full JSON format) where the objects in the above output would be the line ending with a :, so:

  • User:
  • Delegate:
  • Status:

And then each would return their respective values.

I’ve played around with some aggregators, Transform to JSON etc, without much luck. I think i need to perform some regex magic.

Idea would also be i would be able to reuse the regex etc on some other commands i run, with different output.

Thanks

Welcome to the Make community!

You can use a Text Parser “Match Pattern” module with this Pattern (regular expression):

User: (?<user>.+?)(?:, .+)? Delegate: (?<delegate>.+) Status: (?<status>.+)

Proof https://regex101.com/r/vNgd3V/1

Important Info

  • :warning: Global match must be set to NO!

For more information, see Text Parser in the Make Help Center:

Match Pattern
The Match pattern module enables you to find and extract string elements matching a search pattern from a given text. The search pattern is a regular expression (aka regex or regexp), which is a sequence of characters in which each character is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

Hope this helps! Let me know if there are any further questions or issues.

@samliew

P.S.: Investing some effort into the Make Academy will save you lots of time and frustration using Make.

2 Likes

Perfect! Thank @samliew

For reference, here’s the input/output using what @samliew suggested