Usina BRAdvPL Guide
Sign in
← All topics
CLASSUnder review

JsonObject and JSON handling

JsonObject():New(); o:FromJson(cJson); o:ToJson()

Parses JSON, accesses properties and serializes the object.

JsonObject and JSON handlingAdvPL
01 · OVERVIEW

Overview

JsonObject creates dynamic properties accessible through brackets. FromJson returns NIL on success and error text on failure; the official Character type table does not override that rule. Check parsing before accessing the object, then validate the expected schema. ToJson returns a JSON string without fixed property order guarantees. Documentation records P12 build 131227a from version 13.2.3.6. (Sources: refs. 1–3.)

02 · SYNTAX

Syntax

JsonObject():New(); o:FromJson(cJson); o:ToJson()

Methods

NewCreates an empty object.JsonObject():New()
FromJsonLoads JSON text; NIL indicates success.o:FromJson(cJson)
ToJsonExports the object as a string.o:ToJson() -> cJson
03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed501()
    Local oJson := JsonObject():New()
    Local uError := oJson:FromJson('{"code":"ED01","quantity":3}')
    // NIL represents successful parsing, not failure.
    If ValType(uError) == "U"
        ConOut(oJson:ToJson())
    Else
        ConOut(cValToChar(uError))
    EndIf
    FreeObj(oJson)
Return Nil
Expected result

Serializes the fictional document when parsing succeeds. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Validate field presence and types, size limits and contents before applying rules. Do not log sensitive payloads in full.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. Classe+JsonObject. TDN. Accessed on 2026-10-27.
  2. TOTVS. JsonObject%3AFromJSON. TDN. Accessed on 2026-10-27.
  3. TOTVS. JsonObject%3AToJson. TDN. Accessed on 2026-10-27.
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