r.geomorphon: rewrite JSON profile output to use gjson/parson library#7003
r.geomorphon: rewrite JSON profile output to use gjson/parson library#7003Rhushya wants to merge 5 commits intoOSGeo:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the JSON profile output in r.geomorphon to use the GRASS gjson/parson library instead of manual string formatting, addressing issue #6970. The change improves maintainability by replacing complex indent and comma management with a proper JSON object model.
Changes:
- Switched from manual fprintf-based JSON generation to gjson/parson library API
- Added PARSONLIB dependency to the module's Makefile
- Rewrote write_json() function to build a JSON object tree and serialize it
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| raster/r.geomorphon/Makefile | Added PARSONLIB to link against the parson library |
| raster/r.geomorphon/local_proto.h | Added gjson.h header include for JSON API access |
| raster/r.geomorphon/profile.c | Completely rewrote write_json() to use gjson API instead of manual formatting |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@Rhushya i think you need to at least compile it locally before. Assume your PR. Try it out, know its limits. Have tests that prove what was there before, and what you did now are the same (or fixes something that wasn’t there before. |
|
Hey @echoix, You're absolutely right - I should've tested this properly before submitting. I went back and compiled everything locally in WSL Ubuntu, and here's what I found: Build: Compiled successfully against GRASS 8.3.2 with parson library linked Tests: All passing
Here's a snippet of the JSON output my changes produce: {
"final_results": {
"landform_cat": 4,
"landform_code": "SH",
"landform_name": "shoulder",
"azimuth": 97.85808563
},
"map_info": {
"elevation_name": "test_dem",
"projection": 3
},
"timestamp": "2026-01-31T18:53:35Z",
"generator": "r.geomorphon GRASS GIS 8.3.2"
}What I changed:
The output structure stays exactly the same as before - just cleaner code underneath that's easier to maintain. Same pattern used in |
|
Grass 8.3.2 is very very old. And the current master is more than a year ahead of 8.4 |
|
And json didn't exist at that time |
|
Given how r.geomorphon JSON code is written, this requires more carefulness. Also I did not check the test coverage, but I expect a change like this would have to add more tests. The version mismatch in the last comment is questionable. This PR is a candidate for closing. |
|
Hey ill restart as a new issue i had lot of errors in the commits would delete it and start fresh |
@echoix @petrasovaa
Summary
Fixes #6970
This PR switches r.geomorphon's JSON profile output from manual string formatting to the GRASS JSON wrapper (gjson/parson), improving maintainability and avoiding comma/indent edge cases by building the output via a proper JSON object model.
Changes
$(PARSONLIB)to LIBES for library linking#include <grass/parson/gjson.h>Approach
Following the feedback to keep it simple and focus only on JSON:
prof_*functions (prof_int, prof_sso, etc.) stay the sameTechnical Details
The new implementation:
G_JSON_Objecttree from the existing token array