9

I got an anonymous array which I want to deserialize, here the example of the first array object

[
  { "time":"08:55:54",
    "date":"2016-05-27",
    "timestamp":1464332154807,
    "level":3,
    "message":"registerResourcePath ('', '/sap/bc/ui5_ui5/ui2/ushell/resources/')",
    "details":"","component":"sap.ui.ModuleSystem"},
  {"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"URL prefixes set to:","details":"","component":"sap.ui.ModuleSystem"},
  {"time":"08:55:54","date":"2016-05-27","timestamp":1464332154808,"level":3,"message":"  (default) : /sap/bc/ui5_ui5/ui2/ushell/resources/","details":"","component":"sap.ui.ModuleSystem"}
]

I tried deserializing using CL_TREX_JSON_SERIALIZER, but it is corrupt and does not work with my JSON, here is why

Then I tried /UI2/CL_JSON, but it needs a "structure" that perfectly fits the object given by the JSON Object. "Structure" means in my case an internal table of objects with the attributes time, date, timestamp, level, messageanddetails. And there was the problem: it does not properly handle references and uses class description to describe the field assigned to the field-symbol. Since I can not have a list of objects but only a list of references to objects that solution also doesn't works.

As a third attempt I tried with the CALL TRANSFORMATION as described by Horst Keller, but with this method I was not able to read in an anonymous array, and here is why

My major points:

  • I do not want to change the JSON, since that is what I get from sap.ui.log
  • I prefere to use built-in functionality and not a thirdparty framework
4
  • Have you tried this?
    – Jagger
    May 31, 2016 at 8:34
  • @Jagger Yes it bases on the Call transformation which needs (by the syntax CALL TRANSFORMATION demo_st_json_table SOURCE XML json RESULT carriers = result.) a named root node (in this case carriers) I do not have with my annonymous array. May 31, 2016 at 8:43
  • Would a change of the json "on the fly" be acceptable? I would read this json into a string (assuming it is always that small) and then glue "anonymous" : { at the beginning and } at the end. Then try to use CALL TRANSFORMATION for whatever you need and strip this glued parts in the output if needed at all.
    – Jagger
    May 31, 2016 at 8:53
  • @Jagger it will get very long. It is the clientlog of an ui5 application (2000 of those obects?). And I would prefer to not use such a hack. It could be a solution. A parser would be an other approach May 31, 2016 at 9:06

2 Answers 2

2

Your problem comes out not from the anonymity of array, but from the awkwardness of SAP JSON (De)serializer, which doesn't respect double quotes, which enclose JSON attributes. The issue is thoroughly described in this answer.
If you don't want to change your JSON on-the-fly, the only way you have is to change CL_TREX_JSON_DESERIALIZER class like this.

2

/UI5/CL_JSON_PARSER parses JSONs with unknown format.

Note that it's got "for internal use" written on it so many times that you probably should take it seriously and clone its code to fixate it.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.