---
schema_version: "1"
id: 56224f38723a0538059b3d25503f7c566aeba207ad40ec6265f2505984c47e01
title: Migrating the For Each Scope
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/4.3/migration-core-foreach.md
canonical_url: https://docs.mulesoft.com/mule-runtime/4.3/migration-core-foreach
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 03b97c280b04291cfb62122283334bc1d5996fb44ed29e2f0138a821c59c05ea
description: MuleSoft Documentation Site
release: "4.3"
latest: false
---
---
product: Mule Runtime
version: 4.3
---

# Migrating the For Each Scope

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Little changed between For Each scope for Mule 3 and Mule 4 except for the use of DataWeave 2 as the
expression language. This little change however has a huge impact in terms of usability of the
component.

In Mule 3, foreach required the input collection to be a Java Iterable, Java Iterator or Java array.
You were always forced to make sure that the input was in Java format (and therefore, you were
forced to know java).

In Mule 4, we support iterating over any array-like structure, regardless of the format. For
example, suppose the following JSON is posted through an HTTP request:

```json
{
  "persons": [
    {
      "name": "John Doe",
      "age": 34
    },
    {
      "name": "Jane Doe",
      "age": 32
    }
  ]
}
```

Mule 3 requires the json being transformed to Java first:

Mule 3 example

```xml
<flow name="persons">
  <http:listener path="person" method="POST" config-ref="http">
  <json:json-to-object-transformer />
  <foreach batchSize="10" collection="#[payload.persons]">
    <flow-ref name="processPerson" />
  </foreach>
</flow>
```

In Mule 4, you can just access the persons array in Json format directly:

Mule 4 example

```xml
<flow name="persons">
  <http:listener path="person" method="POST" config-ref="http">
  <foreach batchSize="10" collection="#[payload.persons]">
    <flow-ref name="processPerson" />
  </foreach>
</flow>
```

## See Also

- [Migrating Exception Strategies](https://docs.mulesoft.com/mule-runtime/4.3/migration-core-exception-strategies)

- [Migrating from DataWeave 1.0 to 2.x](https://docs.mulesoft.com/mule-runtime/4.3/migration-dataweave)
