Replacing json11?

Hiya-

I’ve recently struggled to write a pass that consumes JSON output from GitHub - Silimate/liberty2json: Liberty to JSON converter as part of contract work. Because Yosys already uses json11, I elected to just use the library Yosys is already compiling and linking against because why not?

This lead me to discovering two limitations with the library:

  1. Lack of typing ergonomics: json11 will return a non-specific default value of a certain type. 0, '', {}, [], you name it. You have to opt-in to check if the key exists, then check it’s of the correct type, THEN check:

       std::string err;
       const std::string json_str = R"({"key1":"value1", "key2":42, "key3":[1, 2]})";
       Json json_obj = Json::parse(json_str, err);
    
       std::cout << '\'' << json_obj["key4"].string_value() << '\'' << std::endl; // ''
    
  2. Poor error reporting experience

    Other JSON libraries have the concept of a JSON pointer you can use to pinpoint where a type error would be, but here you have to manually keep a “key path” so you can successfully communicate to a user where exactly an error might be.

json11 appears to be an unmaintained library now, so I’m wondering if maintainers would be amenable to a replacement with either RapidJSON or nlohmann::json? Both have better validation capabilities - though RapidJSON is performance-focused and nlohmann::json is ergonomics-focused.

I think Yosys uses JSON in very simple ways so I don’t foresee issues with what we have, but PRs are welcome if anybody does find value in switching the implementation over to something else