Handling Mixed / Dynamic JSON Response from Odoo REST API in Mendix

0
Hi Everyone,I am consuming a REST API from Odoo, and the response contains mixed data types such as arrays, objects, and varying JSON structures within the same response.For example, part of the response looks like this: { "id": 6, "product_id": [ 1, "sample" ], "product_uom_qty": 1.0 } Here, the product_id field is returned as an array containing both an integer and a string.When I try to use this response directly in Mendix (using JSON Structure and Import Mapping), it does not allow inconsistent or mixed data types. Mendix expects a fixed and well-defined JSON structure.Currently, I am using a Python service to:Restructure the JSONNormalize mixed data typesSplit complex structures before sending the response to Mendix.However, I would like to avoid this intermediate Python layer.My Questions:Is there a way to handle mixed-type or dynamic JSON responses directly in Mendix without using an intermediate service?What is the recommended approach in Mendix to manage dynamic or inconsistent JSON structures in Import Mapping?Is it possible to parse such responses using a generic object or string handling approach inside a microflow?Any suggestions, best practices, or alternative approaches would be greatly appreciated.Thank you in advance!
asked
2 answers
0

hi,


Mendix Import Mappings require a fixed JSON schema and do not support mixed or dynamic value types in the same field. In your example:


"product_id": [1, "sample"]

This array contains both an integer and a string — that is not supported by Mendix import mapping. The JSON parser determines type based on the first element and expects the rest to be the same type. Mixed arrays like this are flagged as unsupported.

Why this happens

  • Mendix JSON Structures only support arrays of the same type (e.g., all numbers or all objects). Mixed arrays are not mapped.
  • Import Mapping builds domain objects based on the schema it generates from the sample JSON — if the types are inconsistent, the schema cannot be generated reliably.

approaches

1) Normalize the response before mapping

Transform the REST response into a consistent format before import mapping:

  • If product_id always has two parts (id and name), handle it as a list of strings:

"product_id": ["1", "sample"]
  • Then map it to a list of String in Mendix.
  • Or restructure it as:

"product_id": {"id": 1, "name": "sample"}
  • This way you can map it directly to a Mendix object with attributes Id and Name.

This restructure must happen before the Import Mapping step.

2) Manually parse JSON without Import Mapping

If the structure truly varies and you cannot predict it:

  • Retrieve the REST response into a String variable
  • Use a JSON parsing library or community JSON module
  • Manually read values in a microflow (e.g., JSONPath)

This bypasses Import Mapping, giving full control over mixed types.

3) Use a JSON helper (module) or Java action

For truly dynamic or deeply inconsistent JSON:

  • You can use a custom Java action to parse the JSON using JsonNode or similar tools
  • Or use a JSON helper module from the Marketplace to work with dynamic keys and types

These approaches avoid strict import mapping and let you handle any type.

professional

  • Mendix Import Mapping cannot handle mixed-type arrays (default behavior per JSON Structures).
  • Best practice is to normalize the API response into a consistent format (e.g., object or list of same-type values).
  • If normalization isn’t possible, parse the raw JSON in a microflow or Java action manually.


answered
0

https://community.mendix.com/link/spaces/integrations/questions/140171
Expert Stephan’s solution in this link directly addresses your issue with mapping array-type fields. He explains that Mendix cannot handle dynamic attributes where the same field has different types (for example, sometimes a number and sometimes an array). Instead of mapping the array field directly in the Import Mapping, he recommends storing the raw JSON as a string and then extracting the dynamic values using JSON Path or additional parsing logic.


This approach applies to your case as well, because your product_id field is returned as an array with mixed types. Therefore, instead of trying to map it directly, you should handle it separately using JSON Path or custom parsing after receiving the response.


answered