The order is getting changed while using JSON DT.

JSONDT Configuration:
Used automapalldata as an object.
Outcome:

  • In the JSON data, the sequence is not appearing in the expected page format.

  • Before the JSON data is triggered, the order appears correctly in the tracer (MappingData).

  • However, when the JSONDT is triggered, the order does not follow the expected sequence.

    {
    “CaseID”: ***,
    “TempPagelist”: [
    {
    “status”: null,
    “address”: null
    },
    {
    “status”: null,
    “address”: null
    }
    ],
    “response”: 200,
    “status”: “good”,
    “id”: 1
    }

    MappingData Transform:

  • In the single page, all 4 properties are mapped, and then the TempPagelist values are appended.

  • However, the final outcome does not match the expected sequence in the mapping data transform.

    Has anyone encountered a similar issue or have insights into what might be causing this? Please provide input.

    Pega Version: PegaInfinity’23

@NikitaK7 :warning: This is a GenAI-powered tool. All generated answers require validation against the provided references.

I can confirm that what you’re experiencing is actually by design rather than a bug.

JSON Specification References

  1. RFC 8259 - The JavaScript Object Notation (JSON) Data Interchange Format
    • Section on JSON Objects explicitly states: “An object is an unordered collection of zero or more name/value pairs”
    • This is the official Internet Standard for JSON published in December 2017
    • RFC 8259 Specification
  2. ECMA-404 - The JSON Data Interchange Syntax
    • Aligns with RFC 8259 and similarly does not require implementations to maintain property order
    • ECMA-404 Specification

Pega Documentation References

  1. Automapping JSON Data
  2. JSON Data Transforms

Industry Implementation Information

  1. Java/Jackson JSON Serialization
    • Jackson library (commonly used for JSON processing) offers specific annotations like @JsonPropertyOrder precisely because order isn’t guaranteed by default
    • Without explicit ordering configuration, property order depends on the implementation
  2. JavaScript JSON.stringify()
    • Even in JavaScript, where JSON originated, controlling property order requires special parameters to JSON.stringify()
    • Standard behavior doesn’t guarantee preservation of insertion order

Workaround Approaches

since JSON property order typically can’t be controlled directly in Pega JSON Data Transforms, alternative approaches include:

  1. Manual JSON construction using string manipulation
  2. Post-processing to reorder properties after JSONDT generation
  3. Handling ordering logic in the consuming component rather than the JSON itself
  4. Using external JSON libraries with more ordering control options

Above references confirm that what you’re experiencing is indeed by design rather than a bug.

The JSON specification itself doesn’t require maintaining property order, which is why different JSON processors (including Pega’s implementation) might handle ordering differently.

Why JSON Property Order Changes

The behavior you’re observing where “the order does not follow the expected sequence” when using JSONDT with automapalldata occurs because JSON objects are inherently unordered collections of key/value pairs. When Pega serializes data to JSON using the JSON Data Transform, it doesn’t guarantee that the property order in the output will match the order in which properties were defined or mapped.

This is consistent across Pega Infinity’23, where the focus is on the integrity of data mapping rather than preserving the order of properties. The JSON specification itself doesn’t require implementations to maintain property order, which is why different JSON libraries and processors may handle ordering differently.

Workaround Options

Since there’s no built-in way to control property order in JSON Data Transforms, you’ll need to consider one of these alternative approaches:

  1. Manual JSON Construction: Create a custom activity that builds the JSON string manually in the exact order you need. This would involve using String manipulation techniques to construct the JSON with properties in your desired sequence.
  2. Post-Processing: Generate the JSON using the standard JSONDT, then use a post-processing step to reorder the properties according to your requirements. This might involve parsing the generated JSON back into a structure that can be reordered, then serializing again.
  3. Server-Side Rendering Logic: If the order matters for display purposes, consider handling the ordering logic in whatever consumes the JSON rather than in the JSON itself.
  4. External JSON Library: For complex cases, you might consider using an external JSON library that offers more control over serialization options, though this would require more custom implementation.

Impact Considerations

Since JSON property order typically shouldn’t matter for standard JSON processing (most JSON parsers don’t guarantee preserving order), it’s worth examining why the order is important in your specific case:

  • If it’s for data compatibility with an external system that expects a specific order
  • If it’s for human readability in debugging or reporting scenarios
  • If it’s for a custom parser that depends on property order

Understanding the specific requirement might help determine the most appropriate solution.