How can I maintain custom order of properties in Azure Cosmos DB instead of alphabetical order?

Harshit Gupta 60 Reputation points
2025-04-14T05:58:10.81+00:00

In Cosmos DB, I want to store properties like 1. Key, 2. Inside, etc., in the order I define. However, Cosmos DB seems to automatically sort them alphabetically, which creates issues — especially when these documents are passed to LLMs that rely on the order of keys. Is there a way to prevent Cosmos DB from reordering the properties alphabetically? Or is there a recommended data structure approach that preserves the intended order?

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,843 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.