GRASS GSoC 2024 Add JSON output

From GRASS-Wiki
Revision as of 19:25, 22 August 2024 by Juno (talk | contribs)
Jump to navigation Jump to search

Accepted Google Summer of Code 2024 project.

Student Name: Kriti Birda
Organization: OSGeo - Open Source Geospatial Foundation
Mentor Name: Corey White and Vaclav Petras
Title: Add JSON output to different GRASS tools in C
Abstract
At the moment, most of the tools in Grass have custom human readable outputs in plain text. Some of these modules could benefit from storing their output in a portable and commonly used data format. The aim of my project is to use the parson library in various tools so that they can produce JSON outputs. The addition of JSON as an output format will be accompanied with addition of Python test cases to verify the output works as intended and to avoid regressions in future. An option to specify the desired output format (plain or JSON) will also be added to each of the tools updated. The layout of the JSON format will be discussed with mentors prior to implementation and will be optimized towards easy ingestion with Pandas.

Pull Requests

Module PR Title PR Link Status at end of GSoC Period
lib add standard parser option for JSON formatting https://github.com/OSGeo/grass/pull/3704/ merged
r.info add JSON output https://github.com/OSGeo/grass/pull/3744/ merged
v.info add JSON output https://github.com/OSGeo/grass/pull/3755/ merged
r.univar add JSON output https://github.com/OSGeo/grass/pull/3783/ merged
v.univar add JSON output https://github.com/OSGeo/grass/pull/3784/ merged
r.profile add JSON output https://github.com/OSGeo/grass/pull/3872/ merged
r.stats add JSON output https://github.com/OSGeo/grass/pull/3884/ open
r.report add JSON output https://github.com/OSGeo/grass/pull/3935/ merged
g.region add JSON output https://github.com/OSGeo/grass/pull/3941/ merged
v.distance add JSON output https://github.com/OSGeo/grass/pull/3942/ open
r.category add JSON output https://github.com/OSGeo/grass/pull/4018/ merged
v.category add JSON output https://github.com/OSGeo/grass/pull/4020/ open
db.describe add JSON output https://github.com/OSGeo/grass/pull/4021/ merged
v.to.db add JSON output https://github.com/OSGeo/grass/pull/4036/ open
g.proj add JSON output https://github.com/OSGeo/grass/pull/4104/ open
r.object.geometry add JSON output https://github.com/OSGeo/grass/pull/4105/ merged
g.region fix ruff lint error in tests https://github.com/OSGeo/grass/pull/4167/ merged
db.describe fix illegal memory access report https://github.com/OSGeo/grass/pull/4202/ merged

Reports

Introduction: https://discourse.osgeo.org/t/gsoc-2024-introduction-juno/28253

Community Bonding Period: https://discourse.osgeo.org/t/gsoc-2024-week-0-report-add-json-support-to-grass-modules/28299

  1. Week 1: https://discourse.osgeo.org/t/gsoc-2024-week-1-report-add-json-support-to-grass-modules/30673
  2. Week 2: https://discourse.osgeo.org/t/gsoc-2024-week-2-report-add-json-support-to-grass-modules/30764
  3. Week 3: https://discourse.osgeo.org/t/gsoc-2024-week-3-report-add-json-support-to-grass-modules/30791
  4. Week 4: https://discourse.osgeo.org/t/gsoc-2024-week-4-report-add-json-support-to-grass-modules/30834
  5. Week 5: https://discourse.osgeo.org/t/gsoc-2024-week-5-report-add-json-support-to-grass-modules/30882
  6. Week 6: https://discourse.osgeo.org/t/gsoc-2024-week-6-report-add-json-support-to-grass-modules/30906
  7. Week 7: https://discourse.osgeo.org/t/gsoc-2024-week-7-report-add-json-support-to-grass-modules/30946
  8. Week 8: https://discourse.osgeo.org/t/gsoc-2024-week-8-report-add-json-support-to-grass-modules/30993
  9. Week 9: https://discourse.osgeo.org/t/gsoc-2024-week-9-report-add-json-support-to-grass-modules/31007
  10. Week 10: https://discourse.osgeo.org/t/gsoc-2024-week-10-report-add-json-support-to-grass-modules/49643
  11. Week 12: https://discourse.osgeo.org/t/gsoc-2024-week-12-report-add-json-support-to-grass-modules/49735

Final: https://discourse.osgeo.org/t/gsoc-2024-final-report-add-json-output-to-different-tools-in-c/49784

Final Report

The State of the Art Before GSoC

Before this project, the majority of GRASS GIS tools produced outputs in plain text, which required manual parsing or conversion to be used in other software systems. Some modules already had JSON support, but the implementation was inconsistent, using different flags or options. This made it challenging to automate tasks or integrate GRASS GIS outputs directly with modern data processing pipelines.

The Addition (Added Value) That My Project Brought to the Software

The project brought significant improvements by adding JSON output support to 16 GRASS GIS tools. This enhancement allows users to specify their desired output format (plain text or JSON), making it easier to integrate with data analysis tools and workflows. Additionally, the project standardized the options for tools that already had JSON support, improving consistency across the platform. The introduction of comprehensive Python test cases for these outputs ensures that the enhancements are reliable and future-proof.

Potential Future Work

JSON support for 4 modules is currently a work in progress and should hopefully be complete soon. Further work is needed to extend JSON output support to the remaining tools within GRASS GIS. Future developers can build on this foundation, focusing on additional modules or enhancing the JSON schema to support more complex use cases.

Examples

# Python example with dictionary
# Python example with Pandas
# Bash example with jq