[GRASS-git] [OSGeo/grass] ccf5b4: lib/parser: Escape special characters in --json (#...

Vaclav Petras noreply at github.com
Wed Sep 10 07:13:50 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/OSGeo/grass
  Commit: ccf5b4fb89743155f8ad2fd33962d84e83c326ce
      https://github.com/OSGeo/grass/commit/ccf5b4fb89743155f8ad2fd33962d84e83c326ce
  Author: Vaclav Petras <wenzeslaus at gmail.com>
  Date:   2025-09-10 (Wed, 10 Sep 2025)

  Changed paths:
    M lib/gis/parser_json.c
    A lib/gis/tests/conftest.py
    A lib/gis/tests/lib_gis_parser_json_test.py

  Log Message:
  -----------
  lib/parser: Escape special characters in --json (#6310)

The CLI to JSON translator code triggered with --json does not produce valid JSON if there are special JSON characters in parameter values. This adds the escaping to ensure valid JSON output with --json.

This also adds tests, namely a basic test of the functionality, tests based on the main set of examples in the documentation, tests for escapes (which were failing without this change), and tests for two clear error states based on the current implementation. This does not attempt to cover all the cases covered in the code or mentioned in the comments of individual functions.

The JSON escape code comes from v.db.select which is written before the parson addition and combines JSON closely with CSV and other formats, so this is not touching it. The function is specific for this use case and only local to the file, so I made it very specific and included the check in the function, avoiding the repetition of the escaped character. It is assuming that the character presence check is cheaper than an allocation.



To unsubscribe from these emails, change your notification settings at https://github.com/OSGeo/grass/settings/notifications


More information about the grass-commit mailing list