Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

framework.types.json.Compare

framework.types.json.Compare( jJsonObject1, jJsonObject2, [@cRet] ) --> lRet

Compares JSON objects by properties and values.

framework.types.json.CompareAdvPL
01 · OVERVIEW

Overview

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)

02 · SYNTAX

Syntax

framework.types.json.Compare( jJsonObject1, jJsonObject2, [@cRet] ) --> lRet

Parameters

jJsonObject1
JSON / ArrayRequired

Comparison base.

jJsonObject2
JSON / ArrayRequired

Object/array of the same type as the base.

cRet
CharacterOptional

Diagnostic passed by reference.

Return value

Logical comparison result; cRet can receive diagnostics by reference.

03 · PRACTICAL EXAMPLE

Commented example

#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 Nil
Expected result

True 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.

BEST PRACTICES
  • Validate parsing of external input and interpret diagnostics. Comparison establishes neither business validity nor data authenticity.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. framework.types.json.Compare. TDN. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha