# Extract a long text to parse in JSON

**URL:** <https://community.make.com/t/extract-a-long-text-to-parse-in-json/71471>\
**Category:** Questions\
**Tags:** regular-expressions, text-parser, json\
**Created:** [February 25, 2025, 8:20pm UTC](https://community.make.com/t/extract-a-long-text-to-parse-in-json/71471 "2025-02-25T20:20:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NicoM](https://avatars.discourse-cdn.com/v4/letter/n/958977/32.png) [@NicoM](https://community.make.com/u/NicoM)\
**Post date:** [February 25, 2025, 8:20pm UTC](https://community.make.com/t/extract-a-long-text-to-parse-in-json/71471/1 "2025-02-25T20:20:09Z")

</div>

I am using Claude to generate some content.  
I specified the output format as strictly JSON with the format.  
Overall it respects very well the format

```auto
{
    "Activity": [
        {
            "Title_activity": "",
            "Description_activity": ""
        }
      ]
}

```

The only problem is often it had some copy before my code like:

```auto
HERE IS THE CODE / generation / jsonformat etc....
{
    "Activity": [
        {
            "Title_activity": "",
            "Description_activity": ""
        }
      ]
}

```

To parse it properly I want to either remove anything before `{"Activity": [` or select all the text from `{"Activity": [` to the end.  
I tried the lastest, and I use the following regex: `\{[\s\S]*?"Activity": \[(.*\n)+}`  
validated with [regex101.com](http://regex101.com) but I have this output:

```auto
 {
            "Title_activity": "Chasse",
            "Description_activity": "Transformez"
        },
        {
            "Title_activity": "Récit ",
            "Description_activity": "Racontez"
        },
        {
            "Title_activity": "Photographie",
            "Description_activity": "Utilisez votre téléphone"
        },
        {
            "Title_activity": "Souterrain",
            "Description_activity": "Amusez-vous"
        }
    ]

```

which is incorrect as it is missing the beginning of my code:

```auto
{
    "Activity": [

```

And the `}` at the end  
I am not sure how to approach this, it is a very long text to extract and the text before the JSON is random  
I’ve attached the blueprint, data is passed in scenario input  
many thanks  
[blueprint.json](https://community.make.com/uploads/short-url/1HnIRIcrZvMi3lSsWHb4ZjCxqD4.json) (6.0 KB)

---

<div class="post-metadata">

**Author:** ![NicoM](https://avatars.discourse-cdn.com/v4/letter/n/958977/32.png) [@NicoM](https://community.make.com/u/NicoM)\
**Post date:** [February 25, 2025, 8:41pm UTC](https://community.make.com/t/extract-a-long-text-to-parse-in-json/71471/2 "2025-02-25T20:41:19Z")

</div>

Just after posting I had this post suggested: [Stuck with REGEX to extract JSON object](https://community.make.com/t/stuck-with-regex-to-extract-json-object/34341)

I used bit of the regex to amend mine and managed to make it work: `({[\w\W]*?"Activity": \[(.*\n)+?})`  
The only thing strange is that I have 2 value $1 and $2  
$1 give me exactly the JSON i want  
$2 has this value: ]  
I am not sure why, I am using $1 and i am able to parse it to a JSON module after; I am going to run a few more test to ensure it s working properly.  
If someone has a better/more safe approach, to what i did to ensure I can extract a JSON properly all the time, I am happy to hear 🙂  
I will leave the post open 24hrs and mark it with this response if no reply  
Thanks

 ![Screenshot 2025-02-25 at 21.36.52](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/0/2/027ead121d45f158083984ac5ea8083bdb60370c.png)

---

<div class="post-metadata">

**Author:** ![samliew](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/samliew/32/13327_2.png) [@samliew](https://community.make.com/u/samliew)\
**Post date:** [February 26, 2025, 2:49am UTC](https://community.make.com/t/extract-a-long-text-to-parse-in-json/71471/3 "2025-02-26T02:49:20Z")

</div>

> [@NicoM](#):
>
> $2 has this value: ]

That’s because you have a second capturing group.

To omit it, you can use this regex instead.

![](https://europe1.discourse-cdn.com/flex013/uploads/make/original/3X/3/a/3a0c58927f26b0aa42ae058e92d98af878686a3a.png)

You can use a Text Parser “[Match Pattern](https://www.make.com/en/help/tools/text-parser)” module with this Pattern (regular expression):

```plaintext
(?<json>{[\w\W]*?"Activity": \[(?:.*\n)+?})

```

**Proof** [https://regex101.com/r/i5fqQx/1](https://regex101.com/r/i5fqQx/1)

### Important Info

- ⚠ **Global match** must be set to **NO**!

* * *

For more information, see [Text Parser](https://www.make.com/en/help/tools/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](https://en.wikipedia.org/wiki/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.
> 
> - The complete list of metacharacters can be found on the [MDN web docs website](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions).
> - For a tutorial on how to create regular expressions, we recommend the [RegexOne website](https://regexone.com/).
> - For an easy, quick regex generator, try the [Regular Expressions generator](https://regex-generator.olafneumann.org/).
> - For experimenting with regular expressions, we recommend the [regular expressions 101 website](https://regex101.com/). Just make sure to tick the ECMAScript (JavaScript) FLAVOR in the left panel.

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

— @samliew

P.S.: Investing some effort into the [Make Academy](https://academy.make.com) will save you lots of time and frustration using Make.

---

<div class="post-metadata">

**Author:** ![NicoM](https://avatars.discourse-cdn.com/v4/letter/n/958977/32.png) [@NicoM](https://community.make.com/u/NicoM)\
**Post date:** [February 26, 2025, 8:25am UTC](https://community.make.com/t/extract-a-long-text-to-parse-in-json/71471/4 "2025-02-26T08:25:44Z")

</div>

Thank you @samliew works like a charm!

---

<div class="post-metadata">

**Author:** ![Make\_Bot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/make_bot/32/14661_2.png) [@Make\_Bot](https://community.make.com/u/Make_Bot)\
**Post date:** [March 12, 2025, 8:31am UTC](https://community.make.com/t/extract-a-long-text-to-parse-in-json/71471/5 "2025-03-12T08:31:55Z")

</div>


