Handling a dot in JSON field names

0
We have microflows that post JSON to an external server.In some cases, the posted JSON contains dictionaries where field names contain a dot (period); such a field name might be max.buffers.The export (and import mapping) handles field names that optionally contain a space, but not a dot.This forces us to build the JSON to be posted, and modify the JSON manually before posting, rather than using export mapping as intended.Is there any better way than the above?
asked
1 answers
1

Hi Josef,

Unfortunately, this is a limitation of Mendix Import/Export Mappings. Field names containing a dot (.) are interpreted as path separators in the mapping structure rather than literal property names, so keys such as:


JSON



{

"max.buffers": 100

}

cannot be mapped directly to an entity attribute through the standard mapping editor.

In practice, I've seen three approaches:

1. Post-process the JSON (your current approach)

Export using a normal mapping and then replace:


JSON



{

"max_buffers": 100

}

with:


JSON



{

"max.buffers": 100

}

before sending it.

2. Build the JSON manually

For a small number of special properties, create the JSON object/string yourself using a microflow or Java action. This avoids fighting the mapping limitations.

3. Use JSON structures only for the supported part and inject the dotted keys afterwards

This is often the cleanest compromise when most of the payload can be generated by an export mapping and only a few keys contain dots.

If the external API genuinely requires arbitrary dictionary keys (for example configuration settings where the key names are dynamic), I would not model those as entity attributes at all. Instead, I'd store them as key/value pairs and generate the final JSON programmatically.

As far as I know, there is currently no way in the standard Mendix Export/Import Mapping editor to escape a dot and have it treated as a literal character in the JSON property name. So your workaround of modifying the generated JSON before posting is a common solution.

Hope this helps.


answered