diff --git a/src/tree/tree_model.cc b/src/tree/tree_model.cc index 1c8ad0d9e756..a351a8f8be08 100644 --- a/src/tree/tree_model.cc +++ b/src/tree/tree_model.cc @@ -402,7 +402,7 @@ class JsonGenerator : public TreeGenerator { auto cats = GetSplitCategory(tree, nid); static std::string const kCategoryTemplate = R"I( "nodeid": {nid}, "depth": {depth}, "split": "{fname}", )I" - R"I("split_condition": {cond}, "yes", {right}, "no", {left}, )I" + R"I("split_condition": {cond}, "yes": {right}, "no": {left}, )I" R"I("missing", {missing})I"; std::string cats_ptr = "["; for (size_t i = 0; i < cats.size(); ++i) { diff --git a/tests/cpp/tree/test_tree_model.cc b/tests/cpp/tree/test_tree_model.cc index 6bfecfd81149..1bda60241f65 100644 --- a/tests/cpp/tree/test_tree_model.cc +++ b/tests/cpp/tree/test_tree_model.cc @@ -294,6 +294,11 @@ void TestCategoricalTreeDump(std::string format, std::string sep) { ASSERT_NE(pos, std::string::npos); pos = str.find(cond_str, pos + 1); ASSERT_NE(pos, std::string::npos); + + if (format == "json") { + // Make sure it's valid JSON + Json::Load(StringView{str}); + } } } // anonymous namespace