Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: XLFJSON

XLFJSON.m

Go to the documentation of this file.
  1. XLFJSON ;SLC/KCM/TJB - Decode/Encode JSON ;26 Oct 2016
  1. ;;8.0;KERNEL;**680**;Jul 10, 1995;Build 4
  1. ;;Per VA Directive 6402, this routine should not be modified.
  1. ;
  1. ; Note: Since the routines use closed array references, XUROOT and XUERR
  1. ; are used to reduce risk of naming conflicts on the closed array.
  1. ;
  1. DECODE(XUJSON,XUROOT,XUERR) ; Set JSON object into closed array ref XUROOT
  1. ; Examples: D DECODE^XLFJSON("MYJSON","LOCALVAR","LOCALERR")
  1. ; D DECODE^XLFJSON("^MYJSON(1)","^GLO(99)","^TMP($J)")
  1. ;
  1. ; XUJSON: Required; string/array containing serialized JSON object
  1. ; XUROOT: Required; closed array reference for M representation of object
  1. ; XUERR: Optional; closed array reference contains error messages, defaults to ^TMP("XLFJERR",$J)
  1. ;
  1. ; XUIDX: points to next character in JSON string to process
  1. ; XUSTACK: manages stack of subscripts
  1. ; XUPROP: true if next string is property name, otherwise treat as value
  1. ;
  1. G DIRECT^XLFJSOND
  1. ;
  1. ENCODE(XUROOT,XUJSON,XUERR) ; XUROOT (M structure) --> XUJSON (array of strings)
  1. ; Examples: D ENCODE^XLFJSON("^GLO(99,2)","^TMP($J)")
  1. ; D ENCODE^XLFJSON("LOCALVAR","MYJSON","LOCALERR")
  1. ;
  1. ; XUROOT: Required; closed array reference for M representation of object
  1. ; XUJSON: Required; destination variable for the string array formatted as JSON
  1. ; XUERR: Optional; closed array reference contains error messages, defaults to ^TMP("XLFJERR",$J)
  1. ;
  1. G DIRECT^XLFJSONE
  1. ;
  1. ;
  1. ESC(X) ; Escape string for JSON
  1. ; X: Required; String to be escaped
  1. Q $$ESC^XLFJSONE(X)
  1. ;
  1. UES(X) ; Unescape JSON string
  1. ; X: Required; String to be unescaped
  1. Q $$UES^XLFJSOND(X)
  1. ;
  1. ERRX(ID,VAL) ; Set the appropriate error message
  1. ; switch (ID) -- XERRX ends statement
  1. N ERRMSG
  1. ;
  1. ; Decode Error Messages
  1. ;
  1. I ID="STL{" S ERRMSG="Stack too large for new object." G XERRX
  1. I ID="SUF}" S ERRMSG="Stack Underflow - extra } found" G XERRX
  1. I ID="STL[" S ERRMSG="Stack too large for new array." G XERRX
  1. I ID="SUF]" S ERRMSG="Stack Underflow - extra ] found." G XERRX
  1. I ID="OBM" S ERRMSG="Array mismatch - expected ] got }." G XERRX
  1. I ID="ARM" S ERRMSG="Object mismatch - expected } got ]." G XERRX
  1. I ID="MPN" S ERRMSG="Missing property name." G XERRX
  1. I ID="EXT" S ERRMSG="Expected true, got "_VAL G XERRX
  1. I ID="EXF" S ERRMSG="Expected false, got "_VAL G XERRX
  1. I ID="EXN" S ERRMSG="Expected null, got "_VAL G XERRX
  1. I ID="TKN" S ERRMSG="Unable to identify type of token, value was "_VAL G XERRX
  1. I ID="SCT" S ERRMSG="Stack mismatch - exit stack level was "_VAL G XERRX
  1. I ID="EIQ" S ERRMSG="Close quote not found before end of input." G XERRX
  1. I ID="EIU" S ERRMSG="Unexpected end of input while unescaping." G XERRX
  1. I ID="RSB" S ERRMSG="Reverse search for \ past beginning of input." G XERRX
  1. I ID="ORN" S ERRMSG="Overrun while scanning name." G XERRX
  1. I ID="OR#" S ERRMSG="Overrun while scanning number." G XERRX
  1. I ID="ORB" S ERRMSG="Overrun while scanning boolean." G XERRX
  1. I ID="ESC" S ERRMSG="Escaped character not recognized"_VAL G XERRX
  1. I ID="NOV" S ERRMSG="Expected value, got "_VAL G XERRX
  1. ;
  1. ; Encode Error Messages
  1. ;
  1. I ID="SOB" S ERRMSG="Unable to serialize node as object, value was "_VAL G XERRX
  1. I ID="SAR" S ERRMSG="Unable to serialize node as array, value was "_VAL G XERRX
  1. S ERRMSG="Unspecified error "_ID_" "_$G(VAL)
  1. XERRX ; end switch
  1. S @XUERR@(0)=$G(@XUERR@(0))+1
  1. S @XUERR@(@XUERR@(0))=ERRMSG
  1. S XUERRORS=XUERRORS+1
  1. Q