ajson icon indicating copy to clipboard operation
ajson copied to clipboard

Add option to `stringify` for trailing commas

Open mbtools opened this issue 1 year ago • 0 comments

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",
}

mbtools avatar Sep 07 '24 16:09 mbtools