@abapify/asjson-parser 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +101 -0
  2. package/package.json +1 -1
  3. package/CHANGELOG.md +0 -11
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # ABAP asJSON Parser
2
+
3
+ [asJSON](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_asjson.htm) - Canonical JSON Representation
4
+
5
+ General asJSON format is based on `%heap` object delivering values and type metadata
6
+
7
+ So when we have a code like this:
8
+
9
+ ```abap
10
+ REPORT ZTEST_HEAP.
11
+
12
+ start-of-selection.
13
+
14
+ types:
15
+ begin of payload_ts,
16
+ i type i,
17
+ i_ref type ref to i,
18
+ end of payload_ts.
19
+
20
+
21
+ data(payload) = value payload_ts(
22
+ i = 123
23
+ i_ref = new #( 123 )
24
+ ).
25
+
26
+ data(json) = cl_sxml_string_writer=>create( if_sxml=>co_xt_json ).
27
+
28
+ call transformation id
29
+ source data = payload
30
+ result xml json.
31
+
32
+ cl_demo_output=>display_json( json = json->get_output( ) ).
33
+ ```
34
+
35
+ the output it generates will be:
36
+
37
+ ```json
38
+ {
39
+ "DATA":
40
+ {
41
+ "I":123,
42
+ "I_REF":
43
+ {
44
+ "%ref":"#d1"
45
+ }
46
+ },
47
+ "%heap":
48
+ {
49
+ "d1":
50
+ {
51
+ "%type":"xsd:int",
52
+ "%val":123
53
+ }
54
+ }
55
+ ```
56
+
57
+ The following library allows us to parse this payload as if we would deal with a regular ABAP object without data references
58
+
59
+ The code below
60
+
61
+ ```ts
62
+ import { parse } from '@abapify/asjson-parser';
63
+ const parser;
64
+ console.log(parse(json));
65
+ ```
66
+
67
+ would print the object like this:
68
+
69
+ ```json
70
+ {
71
+ "DATA":
72
+ {
73
+ "I":123,
74
+ "I_REF": 123
75
+ }
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ - as a parser
81
+
82
+ ```ts
83
+ import { parse } from '@abapify/asjson-parser';
84
+ console.log(parse(json));
85
+ ```
86
+
87
+ - as a transformer
88
+
89
+ ```ts
90
+ import { fromAbapJson } from '@abapify/asjson-parser';
91
+ const object = JSON.parse(json);
92
+ console.log(fromAbapJson(object));
93
+ ```
94
+
95
+ - as a proxy
96
+
97
+ ```ts
98
+ import { fromAbapJsonProxy } from '@abapify/asjson-parser';
99
+ const object = JSON.parse(json);
100
+ console.log(new Proxy(object, fromAbapJsonProxy));
101
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abapify/asjson-parser",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "dependencies": {},
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
package/CHANGELOG.md DELETED
@@ -1,11 +0,0 @@
1
- ## 0.0.4 (2024-10-07)
2
-
3
- This was a version bump only, there were no code changes.
4
-
5
- ## 0.0.3 (2024-10-07)
6
-
7
- This was a version bump only, there were no code changes.
8
-
9
- ## 0.0.2 (2024-10-07)
10
-
11
- This was a version bump only, there were no code changes.