JSON Shorthands

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
User avatar
eddy
Posts: 124
Joined: Thu Mar 27, 2014 8:34 am

JSON Shorthands

Post by eddy »

it could be like a JSON data section with comma/newline separators:

Code: Select all

; ********** initializing JSON variable ************************
Protected jsonValue, myValue=1                    
DeclareJSON jsonValue                    ;v_jsonvalue =
  JSONArray, 1,2,3, EndJSONArray         ;[ 1,2,3, ];
EndDeclareJSON                           ;

DeclareJSON jsonValue                    ;v_jsonvalue =
  JSONObject, "x", 1, EndJSONObject      ;{ "x": 1, };
EndDeclareJSON                           ;

DeclareJSON jsonValue                    ;v_jsonvalue =
  JSONObject                             ;{
    "x", 1                               ;  "x": 1,
    "y", 2.0                             ;  "y": 2.0,   
    "z", "3"                             ;  "z": "3",         
    "u", JSONBool(1)                     ;  "u": true,         
    "w", JSONBool(0)                     ;  "w": false,         
    "arr"                                ;  "arr":              
    JSONArray                            ;  [                  
      myValue                            ;     v_myvalue,
      2                                  ;     2,
      JSONObject,"v",1,EndJSONObject     ;     { "v": 1, },  
    EndJSONArray                         ;  ], 
  EndJSONObject                          ;};
EndDeclareJSON                           ;

; ********** initializing PB JSON variable ************************ 
CreateJSON(10)
DeclareJSON(10)                          ;spider_JSONValue(10).json =
  JSONObject, "x", 1, EndJSONObject      ;{ "x": 1, };
EndDeclareJSON                           ;

Code: Select all

JSONBool(<boolean expression>)
JSONBool(0)     ;true
JSONBool(1)     ;false
JSONBool(x=y)   ;(v_x==v_y?true:false)