Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to stringify for trailing commas #191

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mbtools
Copy link
Contributor

@mbtools mbtools commented Sep 7, 2024

Setting iv_trailing_comma = abap_true adds a comma to the last node of objects and arrays. This reduces diffs when comparing JSON files, for example.

Example:

" regular
lo_json->stringify( iv_indent = 2 ).
{
  "boolean": true,
  "date": "2020-03-15",
  "false": false,
  "float": 123.45,
  "issues": [
    {
      "end": {
        "col": 26,
        "row": 4
      },
      "filename": "./zxxx.prog.abap",
      "key": "indentation",
      "message": "Indentation problem ...",
      "start": {
        "col": 3,
        "row": 4
      }
    },
    {
      "end": {
        "col": 22,
        "row": 3
      },
      "filename": "./zxxx.prog.abap",
      "key": "space_before_dot",
      "message": "Remove space before XXX",
      "start": {
        "col": 21,
        "row": 3
      }
    }
  ],
  "null": null,
  "number": 123,
  "string": "abc"
}
" with trailing commas
lo_json->stringify(
  iv_indent         = 2 
  iv_trailing_comma = abap_true ).
{
  "boolean": true,
  "date": "2020-03-15",
  "false": false,
  "float": 123.45,
  "issues": [
    {
      "end": {
        "col": 26,
        "row": 4,
      },
      "filename": "./zxxx.prog.abap",
      "key": "indentation",
      "message": "Indentation problem ...",
      "start": {
        "col": 3,
        "row": 4,
      },
    },
    {
      "end": {
        "col": 22,
        "row": 3,
      },
      "filename": "./zxxx.prog.abap",
      "key": "space_before_dot",
      "message": "Remove space before XXX",
      "start": {
        "col": 21,
        "row": 3,
      },
    },
  ],
  "null": null,
  "number": 123,
  "string": "abc",
}

Setting `iv_trailing_comma = abap_true` adds a comma to the last node of objects and arrays. This reduces diffs when comparing JSON files, for example.

Example:

- regular

```abap
lo_json->stringify(
  iv_indent         = 2 ).
```

- with trailing commas

```abap
lo_json->stringify(
  iv_indent         = 2 
  iv_trailing_comma = abap_true ).
```


```
@sbcgua
Copy link
Owner

sbcgua commented Oct 21, 2024

Hmmm, tentative ... the goal is good but this means that the output cannot be parsed by the same tool.

@mbtools
Copy link
Contributor Author

mbtools commented Oct 21, 2024

That's why it's an option and not the default. It would be helpful since I'm passing data (several json files) to an external diff tool.

@sbcgua
Copy link
Owner

sbcgua commented Oct 22, 2024

OK ... but then, could you please add a short comment near the parameter that it is "experimental, not backward compatible and blah blah see the docs ..." and also if I could ask you to describe it in the docs as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants