Skip to content

JSON file support#816

Merged
hverhelst merged 11 commits into
stablefrom
JSON
Jun 4, 2025
Merged

JSON file support#816
hverhelst merged 11 commits into
stablefrom
JSON

Conversation

@hverhelst

@hverhelst hverhelst commented Apr 15, 2025

Copy link
Copy Markdown
Member

This PR interfaces the json library for C++.
It adds the module gsJSON, which can be enabled via CMake

cmake . -DGISMO_OPTIONAL="<other modules>;gsJSON"

As shown in the example json_test.cpp, the class is easily used to generate JSON files.

For example, for writing a file, we can do:

gsJSON j;
j["a"] = 2;
j["b"] = 3.0;
j["c"]["d"] = "four";
j["e"] = {"e1", "e2", "e3"};
j["kv"]=gsKnotVector<>(0,1,0,2);
j.save("file.json");

Generating the following file:

{
    "a": 2,
    "b": 3.0,
    "c": {
        "d": "four"
    },
    "e": [
        "e1",
        "e2",
        "e3"
    ],
    "kv": {
        "degree": 1,
        "knots": [
            0.0,
            0.0,
            1.0,
            1.0
        ]
    }

And for reading a file, we can do:

gsJSON j("file.json");
index_t a = j["a"].get<index_t>();
real_t b = j["b"].get<real_t>();
std::string c = j["c"]["d"].get<std::string>();
std::vector<std::string> e = j["e"].get<std::vector<std::string> >();
gsKnotVector<> kv = j["kv"].get<gsKnotVector<>>();

The commit description must be structured as a list follows:

NEW:
Add JSON support

IMPROVED:

FIXED:

API:


Please consider the following checklist before issuing a pull
request:

  • Have you added an explanation of what your changes do and why
    you'd like us to include them?
  • Have you documented any new codes using Doxygen comments?
  • Have you written new tests or examples for your changes?

@hverhelst hverhelst added this to the G+Smo v25.6.0 milestone Apr 15, 2025
@hverhelst hverhelst requested review from filiatra and mmoelle1 April 15, 2025 14:25
@hverhelst hverhelst requested a review from a team as a code owner April 15, 2025 14:25
Comment thread optional/gsJSON/gsJSON.h Outdated
@hverhelst hverhelst merged commit 8a47338 into stable Jun 4, 2025
9 of 10 checks passed
@hverhelst hverhelst deleted the JSON branch June 4, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants