ONLYOFFICE Docs v7.3 released: enhanced forms, SmartArt, new security settings, Watch Window, and more
ONLYOFFICE Docs v7.3 released

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.