jJsonObject1Comparison base.
AdvPL Guideframework.types.json.Compare( jJsonObject1, jJsonObject2, [@cRet] ) --> lRetCompares JSON objects by properties and values.
The function avoids comparing only object text serialization. The page describes comparison independent of property or array order and case-sensitive property names; if array order is contractual, do not assume strict positional equality. It requires LIB 20211004 or later and a TLPP-capable binary. Inputs must share type, JSON/JSON or Array/Array, with documented root-JSON-array caveats. The example only uses simple objects with reordered properties. code and qty are fixed teaching-contract keys preserved across languages. (TOTVS, n.d., ref. 1)
framework.types.json.Compare( jJsonObject1, jJsonObject2, [@cRet] ) --> lRetjJsonObject1Comparison base.
jJsonObject2Object/array of the same type as the base.
cRetDiagnostic passed by reference.
Logical comparison result; cRet can receive diagnostics by reference.
#Include "Protheus.ch"
User Function Ed392()
Local jBase := JsonObject():New()
Local jCompared := JsonObject():New()
Local cDifferences := ""
// Fixed valid JSONs differ only in property order.
jBase:FromJson('{"code":"A","qty":2}')
jCompared:FromJson('{"qty":2,"code":"A"}')
ConOut(cValToChar(framework.types.json.Compare(jBase,jCompared,@cDifferences)))
FreeObj(jBase)
FreeObj(jCompared)
Return NilTrue in a compatible environment; property order does not change this content. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use
Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.