util.JSONObject.remove()

 

util.JSONObject.remove() removes the specified element from the JSON object.

 

Syntax:

 

util.JSONObject.remove("name")

 

Parameters:

 

name

a name part of the element (= the name:value pair)

 

Usage and examples:

 

util.JSONObject.remove() takes the name of the element of the JSON object (= the name:value pair) as the parameter and deletes this element.

 

example code #1

MAIN

  DEFINE json_obj util.JSONObject

    LET json_obj = util.JSONObject.create()

    CALL json_obj.put("address", "5 Brando Street")

    CALL json_obj.remove("address")

    DISPLAY json_obj.get("address")

  CALL fgl_getkey()

END MAIN

 

obtained results #1

 

example code #2

 

MAIN

    DEFINE json_obj util.JSONObject

    DEFINE js STRING

    

    LET json_obj = util.JSONObject.create()

    

    CALL json_obj.put("id", 8723)

    CALL json_obj.put("name", "McMaclum")

    CALL json_obj.put("address", "5 Brando Street")

    CALL json_obj.put("position", "staff")

    LET js =  json_obj.toString()

    DISPLAY util.JSON.format(js)

    

    CALL json_obj.remove("address")

    LET js =  json_obj.toString()

    DISPLAY util.JSON.format(js)

    

  CALL fgl_getkey()

END MAIN

 

obtained results #2

 

example code #3

MAIN

    DEFINE json_obj util.JSONObject

    DEFINE cust_rec RECORD

             cust_num INTEGER,

             cust_name VARCHAR(30),

             cust_address VARCHAR(30),

             order_ids DYNAMIC ARRAY OF INTEGER

         END RECORD

    DEFINE js STRING

    

    LET cust_rec.cust_num = 345

    LET cust_rec.cust_name = "McMaclum"

    LET cust_rec.cust_address = "5 Brando Street"

    LET cust_rec.order_ids[1] = 4732

    LET cust_rec.order_ids[2] = 9834

    

    LET json_obj = util.JSONObject.fromFGL(cust_rec)

    LET js =  json_obj.toString()

    DISPLAY util.JSON.format(js)

    

    CALL json_obj.remove("cust_address")

    LET js =  json_obj.toString()

    DISPLAY util.JSON.format(js)

    

  CALL fgl_getkey()

END MAIN

 

obtained results #3

 

 

 

Example programs:

CVS server: client.querix.com

CVS repository: /lycia_doc_examples

User: client

Project: auxiliary_features/json

Program: util_JSONObject_remove

 

Related articles:

util.JSONObject.put()

util.JSONObject.get()