---
schema_version: "1"
id: 0a1bed1257d15931f05782a5d91e5d344e7e5401775c6fd16074133e7db2ddad
title: Migrating the JSON Module
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/4.4/migration-connectors-json.md
canonical_url: https://docs.mulesoft.com/mule-runtime/4.4/migration-connectors-json
source_site: docs.mulesoft.com
content_type: documentation
content_hash: fcc13f0b7109e0afc0b12ed0899603bc64ae9b70bbd85f8d97bbf569567b1fc4
description: MuleSoft Documentation Site
release: "4.4"
latest: false
---
---
product: Mule Runtime
version: 4.4
---

# Migrating the JSON Module

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

A new JSON module in Mule 4 replaces the one that was bundled in with Mule 3 for schema validation.

To migrate transformations involving JSON, MuleSoft recommends that you use DataWeave.

## Migrating Transformers

In Mule 3, many components required the payload to be a POJO so that its fields could be accessed.
In Mule 4, DataWeave can be used as a query language directly on the JSON payload, which completely
avoids the need to convert the payload to a POJO as an intermediate step.

### JSON to Object Transformer

For mapping rules that are configured for the `json:json-to-object-transformer`, you can express the
rules in DataWeave.

- In Mule 3:

  Example: Mixin used in the Mapper Configuration

  ```java
  public abstract class AppleMixin
  {
      AppleMixin(@JsonProperty("bitten") boolean wasBitten)
      {
          super();
      }

  }
  ```

  Example: Transformer Referencing the Mapper

  ```xml
  <json:mapper name="myMapper">
      <json:mixin mixinClass="org.mule.module.json.transformers.AppleMixin"
                      targetClass="org.mule.tck.testmodels.fruit.Apple"/>
  </json:mapper>

  <flow name="flow">
      <json:json-to-object-transformer returnClass="org.mule.tck.testmodels.fruit.Apple"
                                       mapper-ref="myMapper"/>
  </flow>
  ```

- In Mule 4:

  Example: Using DataWeave as the Mapper

  ```xml
  <flow name="flow">
      <ee:transform>
          <ee:message>
              <ee:set-payload>
                  <![CDATA[%dw 2.0
                      type apple = Object { class: "org.mule.tck.testmodels.fruit.Apple"}
                      output application/java
                      ---
                      {
                          wasBitten = bitten
                      } as apple
                  ]]>
              </ee:set-payload>
          </ee:message>
      </ee:transform>
  </flow>
  ```

You don’t have to define a mapper or a mixin class in Mule 4. The mapping rules are defined using
DataWeave code.

### Object to JSON Transformer

The mapping rules for the `json:object-to-json-transformer` are also expressed using DataWeave:

In Mule 3:

- Example: Transformer with Mixins

  ```xml
  <flow name="flow">
      <json:object-to-json-transformer returnClass="org.mule.tck.testmodels.fruit.Apple">
          <json:serialization-mixin mixinClass="org.mule.module.json.transformers.AppleMixin"
                                    targetClass="org.mule.tck.testmodels.fruit.Apple"/>

      </json:object-to-json-transformer>
  </flow>
  ```

In Mule 4:

- Example: Using DataWeave as the Mapper

  ```xml
  <flow name="flow">
      <ee:transform>
          <ee:message>
              <ee:set-payload>
                  <![CDATA[%dw 2.0
                      output application/json
                      ---
                      {
                          bitten = wasBitten
                      }
                  ]]>
              </ee:set-payload>
          </ee:message>
      </ee:transform>
  </flow>
  ```

In Mule 4 you can set the output format in the transformation. In this case, the expression defines
the output as `application/json`, so the transformation function returns a JSON payload.

## Migrating XSLT Operations

In Mule 4, the JSON module does not provide a component that transforms the JSON based on an XSLT
mapping. Possible ways to handle this case are:

- Migrate the XSLT to a DataWeave transformation (recommended)

- Use XSLT support of the XML module, first converting the payload to XML.

Mule 4 Example: Using XSLT to Transform JSON

```xml
<flow name="flow">
    ...
	<xml-module:xslt-transform>
	    <xml-module:content>#[output application/xml --- payload]</xml-module:content>
	    <xml-module:xslt>
	        (the XSLT transformation) ...
	    </xml-module:xslt>
	</xml-module:xslt-transform>
	...
</flow>
```

## See also

- [JSON Module](https://docs.mulesoft.com/json-module/latest/)

- [DataWeave Language](https://docs.mulesoft.com/mule-runtime/4.4/dataweave)

- [XML Module](https://docs.mulesoft.com/xml-module/latest/)
