Need dedicated support? Click here
Need dedicated support?
Click here

TextPr FromJson error

Do you want to: Report a bug
Problem: I’m trying to get the JSON structure of the document from Docbuilder and then use that json to build up the document again. However, in certain cases, it throws the following errors.

app.js:8 Uncaught TypeError: Cannot read properties of undefined (reading ‘toString’)
at Object.getHexColor (app.js:8:327739)

Here is the code that I m using:

let json = oDocument.ToJSON(true, true, false, true, true, true);
var oDocument = Api.GetDocument();
var oDocumentFromJSON = Api.FromJSON(json);
for(var i=0; i < oDocumentFromJSON.length;i++){
      oDocument.AddElement(i, oDocumentFromJSON[i]);

The problems comes from the following functions

`AscWord.CTextPr.prototype.FromJson` & `AscWord.CTextPr.prototype.ToJson`

with the key argument “color”. In fact when doing ToJson, the “color” value can end up being an empty dictionary. But when doing FromJson, it checks if “color” != null, then it tries to access the values that are undefined. I guess the “highlight” key argument has the same issue.


DocumentBuilder version:
Installation method: docker image: onlyoffice/documentserver:

hello @humbol

Thank you for the information. We are checking the situation.
I will let you know when I get something.

Hello @humbol

I apologize for the long wait.

When testing on version, the Api.toJSON and Api.FromJSON methods work correctly.

  • Update the documentbuilder version
  • If the problem persists in version 7.3.3, please provide step-by-step instructions to reproduce the problem.

Hello Nikolas,

Thanks for taking a look at this. Actually the problem arises very rarely. And I can’t manage to do a small sample to shows it.

However, if you look at the code ToJSON:

            if (this.Color != null)
				oResult["color"] = {};

				if (this.Color.Auto != null)
					oResult["auto"] = this.Color.Auto;
				if (this.Color.r != null)
					oResult["r"] = this.Color.r;
				if (this.Color.g != null)
					oResult["g"] = this.Color.g;
				if (this.Color.b != null)
					oResult["b"] = this.Color.b;

and the code FromJS

	if (oParsedJson["color"] != null)
				this.Color = new AscCommonWord.CDocumentColor(oParsedJson["color"]["r"], oParsedJson["color"]["g"], oParsedJson["color"]["b"], oParsedJson["color"]["auto"]);

Clearly you can see that oParsedJson["color"] may be {}

In that case the arguments new AscCommonWord.CDocumentColor will be undefined which triggers the error that initialy I described.

Either you can try to do a stronger check, our define default values for r , g, b and auto .


Thank you for the additional information
We are checking the situation. I will let you know when I get something.

Hi @humbol

I apologize for the delay in responses.
We have reproduced the issue and added bug 62222 to our internal tracking system.

Thank you for contributing to our product. We will try to fix the bug in the next versions.