MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / toDeterministicJson

Function toDeterministicJson

sdk/js/src/get-compose-hash.ts:91–100  ·  view source on GitHub ↗

* Deterministic JSON serialization following cross-language standards. * - Recursively sorts object keys lexicographically * - Compact output (no spaces) * - Handles special values (NaN, Infinity) by converting them to null * - UTF-8 encoding (default in JavaScript)

(dic: AppCompose)

Source from the content-addressed store, hash-verified

89 * - UTF-8 encoding (default in JavaScript)
90 */
91function toDeterministicJson(dic: AppCompose): string {
92 const ordered = sortObject(dic);
93 return JSON.stringify(ordered, (key, value) => {
94 // Convert NaN and Infinity to null for deterministic output
95 if (typeof value === 'number' && (isNaN(value) || !isFinite(value))) {
96 return null;
97 }
98 return value;
99 }); // Omit the 'space' argument for compact output
100}
101
102export function getComposeHash(app_compose: AppCompose, normalize: boolean = false): string {
103 if (normalize) {

Callers 1

getComposeHashFunction · 0.85

Calls 1

sortObjectFunction · 0.85

Tested by

no test coverage detected