-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGENERATE.JSON
84 lines (84 loc) · 1.93 KB
/
GENERATE.JSON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
SUBROUTINE GENERATE.JSON(ORIGINAL.DOCUMENT.DICT,DOCUMENT.DATA,JSON)
*
GIT.FILENAME = 'GENERATE.JSON'
GIT.REPO = 'https://github.com/Krowemoh/TCL-Utilities.git'
*
* VERSION
*
VERSION = '1'
*
@USER1 = 'GENERATE.JSON'
@USER2 = 'GENERATE.JSON'
*
DOCUMENT.DICT = ORIGINAL.DOCUMENT.DICT
*
NUMBER.OF.ELEMENTS = DCOUNT(DOCUMENT.DICT,@AM)
*
BUFFER = ''
*
FOR I = 1 TO NUMBER.OF.ELEMENTS
IF DOCUMENT.DICT<I> = '' THEN
CONTINUE
END
*
KEY = DOCUMENT.DICT<I,1>
SUPER.KEY = DOCUMENT.DICT<I,2>
*
IF SUPER.KEY = '' THEN
VALUE = DOCUMENT.DATA<I>
*
IF DCOUNT(VALUE,@VM) > 1 THEN
VALUE = RAISE(VALUE)
CALL JSON.CREATE.ARRAY(VALUE)
END
*
CALL JSON.ADD(BUFFER,KEY,VALUE)
*
END ELSE
NUMBER.OF.VALUES = DCOUNT(DOCUMENT.DATA<I>,@VM)
*
ASSOCIATIONS = TRIM(DOCUMENT.DICT<I,3>)
CONVERT ' ' TO @VM IN ASSOCIATIONS
NUMBER.OF.ASSOCIATIONS = DCOUNT(ASSOCIATIONS,@VM)
*
ARRAY = ''
*
FOR J = 1 TO NUMBER.OF.VALUES
OBJ = ''
*
FOR ASSOC.CTR = 1 TO NUMBER.OF.ASSOCIATIONS
ASSOC.POS = ASSOCIATIONS<1,ASSOC.CTR>
*
VALUE = DOCUMENT.DATA<ASSOC.POS,J>
IF DCOUNT(VALUE,@SVM) > 1 THEN
VALUE = RAISE(RAISE(VALUE))
CALL JSON.CREATE.ARRAY(VALUE)
END
*
CALL JSON.ADD(OBJ,DOCUMENT.DICT<ASSOC.POS,1>,VALUE)
NEXT ASSOC.CTR
*
CALL JSON.CREATE.OBJECT(OBJ)
ARRAY<-1> = OBJ
NEXT J
*
CALL JSON.CREATE.ARRAY(ARRAY)
CALL JSON.ADD(BUFFER,SUPER.KEY,ARRAY)
*
FOR ASSOC.CTR = 1 TO NUMBER.OF.ASSOCIATIONS
ASSOC.POS = ASSOCIATIONS<1,ASSOC.CTR>
DOCUMENT.DICT<ASSOC.POS> = ''
NEXT ASSOC.CTR
END
NEXT I
*
CALL JSON.CREATE.OBJECT(BUFFER)
*
JSON = BUFFER
*
RETURN
*
* END OF PROGRAM
*
END
*