sbcgua / ajson

Yet another json parser serializer for ABAP
MIT License
53 stars 16 forks source link

Simplified string version of SET (idea, needs opinions) #108

Closed sbcgua closed 1 year ago

sbcgua commented 2 years ago

For manual structure creation (looks quite typical for various API requests), it could be more readable to use a simplified one-line version of set.

    lo_json->set(
      iv_path = '/a/b'
      iv_val  = 'xyz' ).

vs

lo_json->sets( '/a/b:xyz' ).
" or
lo_json->sets( |/a/b:{ iv_param }| ).

Any thoughts ?

mbtools commented 2 years ago

good idea. I would allow any valid JSON value as the xyz part. no guessing or converting types. maybe setval is better.

sbcgua commented 2 years ago

setval sets setv set_v set2

sbcgua commented 1 year ago

I wonder if there should be syntax to directly set root node ? And how should it looks like ?

e.g. if /a/b/c: 123 is a node, then 123 is directly root ? Or maybe :123 ? On the one hand : is more visible and actually means that there is the empty path, which is root. (by the way /:123 can also be an option). On the other hand such a syntax does not have any equivalents in json. While pure 123 is a valid json ...

mbtools commented 1 year ago

I'm usually defining a corresponding structure and do ABAP to JSON or JSON to ABAP. Sometimes getting values directly. But I don't construct JSON via individual set statements. Still set with '/path:value' looks ok to me. To set a string I would do same method with '/path:"value"'

sbcgua commented 1 year ago

Yeah, it's the matter of use-cases then. I find it potentially useful for setting some constants in API structures (which happen) and also in Unit tests which are usually constructed in code with fixed values.

Anyway the code is ready (#142) welcome to review. At least the docs :))

sbcgua commented 1 year ago

Kind of "syntaxic sugar"

sbcgua commented 1 year ago

for the UTs case, abap sadly does not support multiline strings, like e.g. JS

x = `
hello
world
`
sbcgua commented 1 year ago

I guess this can be closed