Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
[JSON | http://json.org/], as stated on its website, is a lightweight data interchange format. Surprisingly, despite JSON popularity these days, there is not much material to be found on the subject of XML vs. JSON comparison (usability, overhead, performance). Hopefully this will change soon with JSON broadening adoption as a standard  (http://www.cio.de/news/cio_worldnews/2217519/index3.html).At some point, however, I came across an interesting code demonstrating how to use regular expressions in pre-7.0 NW environment, more precisely from SAP R/3 Enterprise (4.70) onwards, using internal JavaScript engine CL_JAVA_SCRIPT ({code:html}ABAP: Using Regex / Regular Expressions in a Pre-Netweaver Release{code}). As JSON is nothing else than a subset of the object literal notation in JavaScript, I switched to thinking of interpreting JSON in the internal NetWeaver JavaScript engine and binding the result to ABAP… So was smartJSON born.Due to the logic how ABAP data are bound to their JavaScript representation (see the documentation for the method {code:html}CL_JAVA_SCRIPT->BIND( ){code}), it may be useful to use an intermediate interface structure in ABAP with string / character (and also possibly packed) types only, very much like a BAPI structure. Data mapped onto the fields of the interface structure can then be converted to / from their actual ABAP data types. It may make sense to use ISO format e.g. for date values in the intermediate ABAP structure for the sake of compatibility with other systems. The report ZSMARTJSON_DEMO demonstrates this as well.  h2. The architecture of the smartJSON library  The library entry point is an ABAP OO front-end ZCL_SMARTJSON_ABAP_PROCESSOR, written in a service-oriented fashion. Actual library code is written in JavaScript and serves the purpose of mapping the data between ABAP proxy object and native JavaScript variables. Parsing and generation of JSON string from a JavaScript variable is done using JSON utility from MooTools framework  (http://mootools.net/). Although it is possible to create a JavaScript object just by assigning a JSON string to a JavaScript variable, using an external parser makes it possible to validate the JSON string. JavaScript source loading has been implemented separately from the main library class. This is due to the fact that scripts may be stored in various ways (in DB, in the file system, in a web server and so on). Default smartJSON library installation package included with this blog uses an application server file system based solution (it was easier to transport using SapLink). However, any kind of storage will be fine as long as functionalities of the class ZCL_SMARTJSON_SCRIPT_LOADER are preserved.  h2. Components of the installation package and deployment procedure  Installation package can be downloaded from the smartJSON project page  (http://code.google.com/p/smartjson/) and contains the following objects: - SAPLink  (http://code.google.com/p/saplink/) nugget file NUGG_SMARTJSON-1.0.nugg. - JavaScript sources for smartJSON library and JSON parser / generator (SMARTJSON.js, JSON.js)  A working SAPlink is required for the installation. I used SAPlink version 0.1.4 for nugget creation. h3. Installation of ABAP OO components Nugget file NUGG_SMARTJSON-1.0.nugg must be imported using SAPLink. It is advisable to create a package ZSMARTJSON manually beforehand as all the objects belong to the ZSMARTJSON namespace. After activation of all the imported objects, JavaScript sources must be imported using report ZSMARTJSON_SCRIPT_EDITOR. h3. Installation of the JavaScript source files Two JavaScript source files must be installed: ** SMARTJSON - actual library code Run the report ZSMARTJSON_SCRIPT_EDITORType script name : “JSON” in capital letters and run the report (F8)Load file JSON.js from unpacked installation packageClick “Save”.
12 Comments