ue_json

work with json format in beas script

 

you can decalre a json object with

declare=j=ue_json

or

instance json j

 

both create the object ue_json

at end you must destroy the object with

destroy=j

 

Function

Description

parse

Parse a string, BSL object or Datastore and create a JSon Object

 

Example: Parse string

instance json j

j.parse={"test1": "Algo","test2": "Benzon"}

messagebox=<j.test1> <j.test2>

This create a Json object with 2 Properties:

The Script return "Algo Benzon"

 

Example Parse string and parse Json object

instance json a

a.parse {    "name":"John",    "age":30,    "cars": [        { "name":"Ford", "models":[ "Fiesta", "Focus", "Mustang" ] },        { "name":"BMW", "models":[ "320", "X3", "X5" ] },        { "name":"Fiat", "models":[ "500", "Panda" ] }    ] }

// create string of all models

setvar=ls_jtest=

for ll_loop=1 to <a.cars.2.models>

 addvar=ls_jtest=<a.cars.2.models.[ll_loop]>

next

// return 320X3X5

messagebox= <ls_jtest>

// return  name,models

messagebox= <a.cars.1.getfieldnames()>

// return "BMW"

messagebox=<a.cars.2.name>

// return "Fiesta"

messagebox=<a.cars.1.models.1>

destroy=a

 

Example: Parse Datastore

instance json j

instance datastore d

d.select="ItemCode","ItemName" from "OITM" where "ItemCode" >= 'RM' and "ItemCode" < 'S'

j.parse=d

Result is the datastore in Json Object, example:
json_example1

 

Example: Parse BSL (beas service layer)

instance json j

instance bsl b

b.Item()?$select=ItemCode,ItemName&$filter=ItemCode gt 'RM' and ItemCode lt 'S'

j.parse=b

 

Limitation:
bsl results with $expand not supported

<string>

return a value from a json object

 

destroy=j

instance json j

j.parse={"Today":"2019/10/05","Color":{"Red":1,"Blue":2,"Green":3},"TestArray":[{"a":1,"b":2}]}

 

// This produce follow object structure

json_example_get1

messagebox=<j.Today>

// Display: 2019/10/05

 

messagebox=<j.Color.Red>

// Display: 1

 

messagebox=<j.TestArray.1.b>

// Display: 2

 

Note: Array functionality support limited

<getfieldnames()>

Current only root level supported

 

destroy=j

instance json j

j.parse={"Today":"2019/10/05","Color":{"Red":1,"Blue":2,"Green":3},"TestArray":[{"a":1,"b":2}]}

messagebox=<j.getfieldnames()>

 

 

<stringify>

Example:

 

instance json j

j.parse={"Color":{"Red":1,"Blue":2,"Green":3}}

j.set=Color.Blue=21

j.set=Color.Yellow=4

messagebox=<j.stringify>

 

// Display: {"Color": {"Red": 1,"Blue": "21","Green": 3,"Yellow": "4"}}

set

setnumber

setboolean

setdate

Generate a json object or change existing json objects

 

Example: Simple json

instance json j

j.set=Hello=world

j.setnumber=TestNumber=1.4

j.setdate=myDateTime=<today> <time>

j.setboolean=TestBoolean=false

 

generate a json with follow result

json_example_set

 

Note:
The json object don't support date or date time fields. Always type "String" generate

If you define the content with "setdate", the system convert this in correct Date/DateTime Json format

Current you can't define arrays or objects

 

Example: Replace field in sub object

 

destroy=j

instance json j

j.parse={"Today":"2019/10/05","Color":{"Red":1,"Blue":2,"Green":3}}

// Replace entry

j.set=Color.Blue=21

// Add Entry

j.set=Color.Yellow=4

 

Result:

json_example_set2

 

 

Example

Create a json object and create 2 properties

 

instance json j

j.set=test1=Algo

j.set=test2=Benzon

messagebox=<j.test1>

// Display: Algo

messagebox=<j.stringify>

// Display complete object:  {"test1": "Algo","test2": "Benzon"}

 

Example

Parse a json string and return values from properties

instance json j

j.parse={"test1":"Algo","test2":"Benzon"}

messagebox=<j.test1>

// Display "Algo"

 

 

Example

Json with SubObject

instance json j

j.parse={"Color": [ {"Red":1}  ,  {"Blue":1}  ] }

messagebox=<j.Color.1.Red>

// Display: 1