Code Monkey home page Code Monkey logo

zjson's Introduction

zjson's People

Contributors

gregorwolf avatar larshp avatar se38 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zjson's Issues

Handle boolean

In case a dataelement is "BOOLEAN", create a boolean value (true/false without quotation marks)

APPEND_DATA: malformed JSON

If you create the JSON document with CREATE_DATA and append a structure with APPEND_DATA, the resulting JSON is malformed (two objects instead of one).

Wrong

{ 
  "f1": "v1", 
  "f2": "v2" 
}, 
"newstructure": { 
  "f3": "v2" 
}

Correct:

{ 
  "f1": "v1", 
  "f2": "v2" ,
  "newstructure": { 
    "f3": "v2" 
  }
}

Handle Data References

As enhancement to "handle complex structure #4":
If the data reference field is already created (by CREATE DATA...) outside of the class, the type is known and the true structure/table/field should be returned in GET_DATA (not only a string like before).

Performance issue when parsing large JSON

Hi,

I noticed when parsing large JSON string there is a performance issue. String that I'm parsing has around 4 000 lines, and creation of the json_doc is about 6 min . Is it possible in this case to create document in shorter time ?

json_doc = zcl_json_document=>create_with_json( my_large_json ).

Best regards,
Marina

Wrap NUMC into quotes

Release: 0.2.24

It seems that NUMC are no longer wrapped into quotes which makes them being handled as integers. This behaviour was not the same in 0.2.0 (which has the same output as ST-PI on the below screenshot)
capture

Actually, in the ADD_DATA method, the NUMC type has been grouped with the Integer and Packed types. Is there a reason fo this?

wdr_simple_name_value_list not present on 7.00 systems

get data as key/value pairs (enhancement #12) doesn't work on 7.00 systems because table type wdr_simple_name_value_list is not present yet.

Choose another table type (prefered) or the zJSON table type (workaround)

!!! change needed also in Neo4a !!!

Syntaxe Issue when a value begins with :

Hello Uwe Fetzer,

I encounter an issue with the library ZCL_JSON_DOCUMENT.
I'm not able to said which version / how old the installation is (I'm working in AMS Team) but I checked in your src folder for method get_json_large and I found the REGEXP which break the JSON syntaxe.

In my installation, I have only get_json but in master version, the get_json call get_json_large.
So I warn you, maybe your library contain the following error :

  • When my field value begins with :, the JSON syntaxe is broken :

image

You can easily reproduce the error and fix the issue (if it still exists in the lastest version).

For the story :

In our usage case, we use the library to generates a JSON answer to a Fiori application (throught a Web Service).
JavaScript will no be able to parse the answer and stop working.
It's blocking for the user.

Action :

I can make the correction on our installation, but I have no idea what is the purpose of the fix sapcodexch issue #3.
Can I removed the REGEXP check ?

Last question, is * in REGEXP stands for "all" ? Maybe I can replace it by "(.*)": ?

Our version :
image

Your version :
image

Thanks a lot for your help.
Kindly regards,

Nicolas DUPRE.

TYPES: BEGIN OF ty_json,
         matnr TYPE matnr,
         maktx TYPE maktx,
       END   OF ty_json.

DATA : lo_json TYPE REF TO zcl_json_document.
DATA : lo_json2 TYPE REF TO zcl_json_document.
DATA : lt_data TYPE TABLE OF ty_json.
DATA : lt_data2 TYPE TABLE OF ty_json.
DATA : lv_json TYPE string.
DATA : lv_json2 TYPE string.

APPEND VALUE #(
  matnr = 'A12345'
  maktx = 'Matnr desc'
) TO lt_data.
APPEND VALUE #(
  matnr = 'A12345'
  maktx = ':Matnr desc'
) TO lt_data2.

CREATE OBJECT lo_json.
CREATE OBJECT lo_json2.

lo_json->set_data(
  suppress_itab = 'X'
  data          = lt_data
).
lo_json2->set_data(
  suppress_itab = 'X'
  data          = lt_data2
).

lv_json = lo_json->get_json( ).
lv_json2 = lo_json2->get_json( ).

WRITE : lv_json. WRITE : / . WRITE : lv_json2.

Not support to UTF-8

There is a critical problem, when there is a UTF-8 characters, when generate to JSON, it seems OK via debug mode, but when transfer out, the characters shows wrong characters. And this is nothing with 'Content-type' setting, as I use another Json class, it works fine without 'Content-type'. So I kindly ask you to fix this issue, I think zJSON is really a very very good tool. Thanks a lot!

Performance Problem on Large Json

I'm encountering severe performance issues with large objects. The server returns ~50 MB of json data, a long array. The parser spends most of its time in ESCAPECHAR and GET_OFFSET_CLOSE. I've the impression that the run time increases with the square of the size of the object.

The culprit is most probably the use of FIND ALL OCCURENCES on the complete object to search for the next un-escaped double quote or closing bracket and the following bracket pairing loop. Wouldn't it be better to implement a one time linear search over the complete document to separate it into its tokens? The result could be a table with start offset / end offset for each item. A regular expression could help to exclude escaped objects in the first place instead of the "what's the character let of me?" check.

Change JSON property Name

Hello Uwe,
First of all thanks for all the work done in this library. Impressive!

I am trying to create the following JSON with zJSON:

{
"electronic_vault_subscription_enabled": true,
"paper_documents_distribution_enabled": true,
"electronic_documents_distribution_enabled": true,
"electronic_payslips_opted_out": true
}

Typically I create a DDIC structure and then use the CREATE_WITH_DATA method to generate the JSON.
Problem here is the length of the JSON property fields since in DDIC structure components have a max size of 30 chars.

I didn't find any method I could use to make a transformation on the property names. Is this possible to achieve with the current stage of zJSON?

Maybe the CREATE_WITH_DATA method could have have an import parameter for name_mappings ? (like it is done in constructor for /UI2/CL_JSON)

Thank you
Sérgio

ZJSON install issue

I am trying to install ZJSON so I can do REST services via ABAP.

I believe I have upgraded to the newest ZSAPLINK_INSTALL and I am trying to run ZSAPLINK from SE38 to install the SAPlink_Daily.nugg file but I get the error "Plugin for object type MSAG is not installed on this system.

I have installed the SAPlink-plugins_Daily.nugg, but that did not install the MSAG plugin.

Is the plugin specific to ABAP for Eclipse? We are using ABAP via the SAPGui, not Eclipse. Do I need to install this?

Is there a step-by-step manual for preparing our system to use these ZJSON functions?

Any assistance would be greatly appreciated.

abap <-> json name mapping not working when converting json to abap table

Hi, first of all, thanks a lot for this great and useful project.

I think I found a bug when trying to convert a complex json to an abap table. In my case it fails and does not return the result (but no error is raised).

I have this json:
[{"crmId":"CRM2022-0011","userId":"718e9fa4-599a-47b6-b66a-2673e30941d4","purchaseDate":"2022-02-25T00:00:00","updateDate":"2022-02-25T10:47:34.983","status":"alta","price":1,"purchaseProducts":[{"crmId":"JUE2","description":"El Test Digital","price":1,"purchaseDate":"2022-02-25T10:27:19.222Z","endDate":"2022-02-25T10:27:19.222Z","appId":"elTest","appSkus":["es.test.test.10"],"rights":[]}],"purchaseInfo":{"email":"[email protected]","password":null,"name":"Test","surname":"Test"},"id":51},{"crmId":"CRM2022-0011","userId":"718e9fa4-599a-47b6-b66a-2673e30941d4","purchaseDate":"2022-02-25T00:00:00","updateDate":"2022-02-25T10:50:36.677","status":"bajaa","price":1,"purchaseProducts":[{"crmId":"JUE2","description":"El Test Digital","price":1,"purchaseDate":"2022-02-25T10:27:19.222Z","endDate":"2022-02-25T10:27:19.222Z","appId":"elTest","appSkus":["es.test.test.10"],"rights":[]}],"purchaseInfo":{"email":"[email protected]","password":null,"name":"Test","surname":"Test"},"id":52},{"crmId":"CRM2022-0011","userId":"718e9fa4-599a-47b6-b66a-2673e30941d4","purchaseDate":"2022-02-25T00:00:00","updateDate":"2022-02-25T11:10:41.56","status":"baja","price":1,"purchaseProducts":[{"crmId":"JUE2","description":"El Test Digital","price":1,"purchaseDate":"2022-02-25T10:27:19.222Z","endDate":"2022-02-25T10:27:19.222Z","appId":"elTest","appSkus":["es.test.test.10"],"rights":[]}],"purchaseInfo":{"email":"[email protected]","password":null,"name":"Test","surname":"Test"},"id":53}]

And this complex abap type:

TYPES: BEGIN OF ts_rights,
         info TYPE string,
       END OF ts_rights,
       tt_rights TYPE STANDARD TABLE OF ts_rights
                      WITH NON-UNIQUE DEFAULT KEY.
TYPES: BEGIN OF ts_purchase_info,
         email    TYPE string,
         password TYPE string,
         name     TYPE string,
         surname  TYPE string,
       END OF ts_purchase_info.
TYPES: BEGIN OF ts_purchase_products,
         crm_id        TYPE string,
         description   TYPE string,
         price         TYPE string,
         purchase_date TYPE string,
         end_date      TYPE string,
         app_id        TYPE string,
         app_skus      TYPE tt_app_skus,
         rights        TYPE tt_rights,
       END OF ts_purchase_products,
       tt_purchase_products TYPE STANDARD TABLE OF ts_purchase_products
                                 WITH NON-UNIQUE DEFAULT KEY.
TYPES: BEGIN OF ts_purchase,
         id                TYPE string,
         crm_id            TYPE string,
         user_id           TYPE string,
         purchase_date     TYPE string,
         update_date       TYPE string,
         status            TYPE string,
         price             TYPE string,
         purchase_products TYPE tt_purchase_products,
         purchase_info     TYPE ts_purchase_info,
       END OF ts_purchase,
       tt_purchase TYPE STANDARD TABLE OF ts_purchase
                        WITH NON-UNIQUE DEFAULT KEY.

When I transform the json to a variable type tt_purchase it returns nothing. Code snippet:

  TRY.
      DATA(lo_json) = zcl_json_document=>create_with_json( json = lv_respuesta
                                                           name_mappings = VALUE #( ( abap_name = 'CRM_ID'            json_name = 'crmId' )
                                                                                    ( abap_name = 'USER_ID'           json_name = 'userId' )
                                                                                    ( abap_name = 'PURCHASE_DATE'     json_name = 'purchaseDate' )
                                                                                    ( abap_name = 'END_DATE'          json_name = 'endDate' )
                                                                                    ( abap_name = 'UPDATE_DATE'       json_name = 'updateDate' )
                                                                                    ( abap_name = 'PURCHASE_PRODUCTS' json_name = 'purchaseProducts' )
                                                                                    ( abap_name = 'PURCHASE_INFO'     json_name = 'purchaseInfo' )
                                                                                    ( abap_name = 'APP_ID'            json_name = 'appId' )
                                                                                    ( abap_name = 'APP_SKUS'          json_name = 'appSkus' ) ) ).
      lo_json->get_data(
        IMPORTING
          data = et_purchase
      ).
    CATCH zcx_json_document INTO DATA(lx_json_document).
      cl_message_helper=>set_msg_vars_for_if_t100_msg( lx_json_document ).
      eo_log->add_message( VALUE #( id = sy-msgid
                                    type = zcx_generic=>gc_message_type-error
                                    number = sy-msgno
                                    message_v1 = sy-msgv1
                                    message_v2 = sy-msgv2
                                    message_v3 = sy-msgv3
                                    message_v4 = sy-msgv4 ) ).
  ENDTRY.

Where lv_respuesta contains the json and et_purchase is the abap table.

I made the following corrections in the private method GET_TABLE of the class ZCL_JSON_DOCUMENT and now its working:
image
When obtaining the values of the structure for the resulting table, it was not applying the mapping from abap to json name (in the method GET_STRU is aplying it).

I post this here in case I'm calling the class in a wrong way and this is really not a bug (but it seems so).

Set new version number

As zJSON is running stable since a couple of years, I think we can set a version number > 0 now

Fieldname mapping with mapping JSON or XSLT

As an enhancement of issue #27 :
Pass a mapping JSON or an XSLT name for fieldname mappings
Example mapping JSON

{
  "abap_fieldname_1" : "JSONFieldNameOne",
  "abap_fieldname_2" : "JSONFieldNameTwo"
}

Float as type P

In Neo4j large numbers (ie. timestamps) are handled as float despite the fact, that they are stored as type P in the SAP system.
If the JSON (float) now is converted back to DATA (P), an exception is raised.

Float has to be converted back to P.

export ZIP error

Our system's object is developed in ZH language. While exporting ZIP file alert an error 'TOBJT no english description' .

ZJSON examples in ABAP

I have to thank you so very much for providing the plugins you have created. I am really hoping they can help me create an ABAP program interface to connect to an external RESTful web service using JSON, but so far, I have been searching everywhere I can think of but I'm not finding any clear examples of how to use this stuff.

Unfortunately, I am a long time ABAP developer and never really got into the web side of things. I understand some concepts regarding HTML and HTTP communication, but REST and JSON are very new to me. Can you please point me to a step-by-step example in ABAP (via SAPGui, not Eclipse and we are not on 7.4 yet) showing exactly how I need to call a REST service?

So far, I am using the CL_HTTP_CLIENT class CREATE_BY_DESTINATION method to open a connection to the external service using Basic Authentication. The base URL is secure.smartwaregroup.com and our path is /Bigfoot/PABCO with various method subpaths depending upon the specific function we need to call.

My trouble spot has been trying to call their /api/login method where I need to pass the LoginName, Password, CultureCode ('en-US'), and Expires (120 minutes) parameters but I'm having trouble with the HTTP / REST / JSON syntax using the ABAP CL_HTTP_CLIENT class.

I have called CL_HTTP_CLIENT->REQUEST->SET_HEADER_FIELD to set the values: '~server_protocol' = 'HTTP/1.1', 'Accept' = 'application/json', and 'Content-Type' = 'application/json; charset=utf-8'.

I have also called CL_HTTP_CLIENT->REQUEST->SET_METHOD to set the method to POST and CL_HTTP_UTILITY=>SET_REQUEST_URI to the full method path /Bigfoot/PABCO/api/login.

I have tried setting the login parameters as form fields, but I think they need it in JSON format, so I then just hardcoded what they expect and called CL_HTTP_CLIENT->REQUEST->SET_CDATA but their server returns a login screen as if my request was rejected. It should instead return a session ID.

Am I on the right track?? Does the SET_CDATA (or SET_DATA) method place the specified content into the "payload" or should I be doing something else?

Thank you so much for any assistance you can provide.

Bryan

handle complex structure

Hi Mr. Uwe Fetzer,

Thank you very much for the awesome project. I've used your code in my mobile project to query data from SAP and display them in my mobile apps and it works wonderfully. Now I'm preparing a method to do dynamic function call and output JSON string, considering it may return dynamical table data, I've to use type ref to data as the data source. But from your code, it doesn't support dref data type. Because in my scenario, whenever I use dref type, it always means I'm referring to internal table, so I managed to solve that by using code like below in your method ADD_DATA of class zcl_json_document:
WHEN data_descr->typekind_dref.
FIELD-SYMBOLS:<fs> type any table.
try.
assign data->* to <fs>.
add_table( <fs> ).
catch cx_root.
endtry.

At present, the test result looks OK, but I'm not familiar with dynamic programming. Do you think it's compatible with your code or not? If not, would you please show me the correct way?

Best Regards,
Jeff

FIND_INFINITE_LOOP + while creating the JSON

While creating a Json using zcl_json_document=>create_with_json. We face the short dump in few cases. Issue might be because statement lv_json = me->json. is not executed properly. Lv_json after this statement is }} where us me->json is having full required json.

Request guidance to close this issue.

image
SD.txt

zabapgit error when pulling objects (see scrshot detailing error attached)

Hello Uwe,

Hope you will be able to resolve as know you are a busy dev.

I attempted twice to load the objects in this github repo ZJSON today via ZABAPGIT. First system was in ABAP 1909 Dev System and second system ABAP NPL 7.52 which showed the same fault/bug?.

Please find attached scrshot when I try to pull (load) the ZJSON objects. Fails when trying to create table ZJSON_KEY_VALUE. System complain it cannot activate. When I try to create Z table manually simulating fields in src xml, I also receive activation error when using KEY (is a reserved word) as field name.

Would kindly appreciate if there is a workaround or solution to this. Thanks in advance,

Please let me know if the scrshot is/not viewable as unsure if PNG format is supported. Can resend with word format. TIA.

Kind regards

Peter Li
Abapgit_pull_error

Russian char

Hi thanks for this nice class. I have a small question:
How to convert Json with foreign language? I can't find any char encoding in method create with data.
If I try to convert structure with russian description field text I obtain this ########### from this Инсталляция.
Please let me know.

Thanks.

Attributes in uppercase?

The kernel implementation produces JSON with attributes in uppercase. As JavaScript is case-sensitive, it makes replacement of zJSON by Kernel implementation (or the contrary) cumbersome as it means handling these different cases of the frontend application.

Wouldn't it be nice to be able to specify whether you want the attributes in lowercase or in uppercase?

Escape Slash

According to json.org the normal slash also has to be escaped / unescaped: "/" -> "/" and vice versa

Error in Hana DB only

Method get_value and get_value_int were working fine the old oracle DB
Currently we have moved to HANA DB and we facing syntax error in both these methods.
Syntax error is on Read statement : READ TABLE me->data ASSIGNING WITH TABLE KEY key = key.
Actual Error : Component "VALUE" of key "PRIMARY_KEY" of table "ME->DATA" is not specified or is incomplete. Key must be specified in full. provided

Please help to resolve the issue.

image

New function: Clear data

If you want to start with a fresh JSON document currently you need to create a new instance.

Enhancement:
new method CLEAR_DATA (or CLEAR_JSON ?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.