How to manipulate a XGBoost JSON model and load it back? [R]

Hi all,
In R, is there a way to save a XGBoost model, modify it (eg: remove splits in decisions trees, or add a tree), and then load it back as an XGBoost Booster object?

I cannot make it work using the JSON route. I am using the XGBoost version ‘1.6.0.1’. Here is my code:

library(xgboost)
data(agaricus.train, package='xgboost')
data(agaricus.test, package='xgboost')
dtrain <- with(agaricus.train, xgb.DMatrix(data, label = label))
dtest <- with(agaricus.test, xgb.DMatrix(data, label = label))
watchlist <- list(train = dtrain, eval = dtest)

## A simple xgb.train example:
param <- list(max_depth = 2, eta = 1, nthread = 2,
              objective = "binary:logistic", eval_metric = "auc")
bst <- xgb.train(param, dtrain, nrounds = 2, watchlist)

# The native saving and loading works
xgb.save(bst, "/tmp/bst.json")
xgb.load("/tmp/bst.json")

# Doing the roundtrip after reading the JSON in R does not work 
json_xgb = jsonlite::read_json("/tmp/bst.json", simplifyVector = FALSE)
jsonlite::write_json(json_xgb, "/tmp/bst2.json", auto_unbox = TRUE)
xgb.load("/tmp/bst2.json")

# Even without changing the trees, I get the error below:
# Error in xgb.Booster.handle(modelfile = modelfile) : 
#   [12:34:07] amalgamation/../src/c_api/c_api.cc:914: Check failed: str[str.size() - 2] == '}' (
#     vs. }) : 
#   Stack trace:
#   [bt] (0) /home/X921342/R-packages/xgboost/libs/xgboost.so(+0x4e719) [0x7fb6dee6c719]
# [bt] (1) /home/X921342/R-packages/xgboost/libs/xgboost.so(+0x114c97) [0x7fb6def32c97]
# [bt] (2) /home/X921342/R-packages/xgboost/libs/xgboost.so(XGBoosterLoadModel+0xe4) [0x7fb6def32df4]
# [bt] (3) /home/X921342/R-packages/xgboost/libs/xgboost.so(XGBoosterLoadModel_R+0x3d) [0x7fb6dee6adcd]
# [bt] (4) /opt/conda/envs/sd-pricing-r/lib/R/lib/libR.so(+0xff70c) [0x7fb6f9a9b70c]
# [bt] (5) /opt/conda/envs/sd-pricing-r/lib/R/lib/libR.so(+0x142998) [0x7fb6f9ade998]
# [bt] (6) /opt/conda/envs/sd-pricing-r/lib/R/lib/libR.so(Rf_eval+0x80) [0x7fb6f9af4560]
# [bt] (7) /opt/conda/envs/sd-pricing-r/lib/R/lib/libR.so(+0x15a2bf) [0x7fb6f9af62bf]
# [bt] (8) /opt/conda/envs/sd-pricing-r/lib/R/lib/libR.so(Rf_applyClosure+0x19e) [0x7fb6f9af708e]