# \[CEA 46521\]\[ROOT 6.36\]\[Python\] Serialisation of TMatrixD with TBufferJSON Issue

**URL:** <https://root-forum.cern.ch/t/cea-46521-root-6-36-python-serialisation-of-tmatrixd-with-tbufferjson-issue/63981>\
**Category:** Newbie\
**Tags:** python, root\
**Created:** [August 5, 2025, 11:54am UTC](https://root-forum.cern.ch/t/cea-46521-root-6-36-python-serialisation-of-tmatrixd-with-tbufferjson-issue/63981 "2025-08-05T11:54:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [August 5, 2025, 11:54am UTC](https://root-forum.cern.ch/t/cea-46521-root-6-36-python-serialisation-of-tmatrixd-with-tbufferjson-issue/63981/1 "2025-08-05T11:54:15Z")

</div>

* * *

_ROOT Version:_ 6.32.14: Passed / 6.36.02: Failed  
_Platform:_ linuxx8664gcc  
_Compiler:_ c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0

* * *

Hello,

## Summary

Serialisation of a `TMatrixD` with `TBufferJSON::ToJSON()` triggers a `Failed to instantiate` error in Python with ROOT 6.36.

## Packages

I tested your packages for Ubuntu 24:

- [https://root.cern/download/root\_v6.32.14.Linux-ubuntu24.04-x86\_64-gcc13.3.tar.gz](https://root.cern/download/root_v6.32.14.Linux-ubuntu24.04-x86_64-gcc13.3.tar.gz)
- [https://root.cern/download/root\_v6.36.02.Linux-ubuntu24.04-x86\_64-gcc13.3.tar.gz](https://root.cern/download/root_v6.36.02.Linux-ubuntu24.04-x86_64-gcc13.3.tar.gz)

## Python Tests

### ROOT 6.32

```bash
$ root -q
   ------------------------------------------------------------------
  | Welcome to ROOT 6.32.14 https://root.cern |
  | (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jun 05 2025, 07:08:58 |
  | From tags/v6-32-14@v6-32-14 |
  | With c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

```

```bash
$ python3 -c "import ROOT; print(ROOT.TBufferJSON.ToJSON(ROOT.TMatrixD()))"
{
  "_typename" : "TMatrixT<double>",
  "fUniqueID" : 0,
  "fBits" : 0,
  "fNrows" : 0,
  "fNcols" : 0,
  "fRowLwb" : 0,
  "fColLwb" : 0,
  "fNelems" : 0,
  "fNrowIndex" : 0,
  "fTol" : 0,
  "fElements" : []
}

```

### ROOT 6.36

```bash
$ root -q
   ------------------------------------------------------------------
  | Welcome to ROOT 6.36.02 https://root.cern |
  | (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jul 08 2025, 22:04:21 |
  | From tags/v6-36-02@v6-36-02 |
  | With c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

```

```bash
$ python3 -c "import ROOT; print(ROOT.TBufferJSON.ToJSON(ROOT.TMatrixD()))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: Template method resolution failed:
  Failed to instantiate "ToJSON()"

```

## Discussions

- Is it the expected behaviour with ROOT 6.36?
  - [ROOT Version 6.36 Release Notes](https://root.cern/doc/v636/release-notes.html) only seems to mention [TBufferJSON not serializing std::map · Issue #18195 · root-project/root · GitHub](https://github.com/root-project/root/issues/18195) which maybe unrelated.

- What is the correct way to serialise a `TMatrixT` with `TBufferJSON` in ROOT 6.36 using Python?

## Note

C++ test passed:

```bash
$ root -q -e "TMatrixD m; TBufferJSON::ToJSON(&m)"
   ------------------------------------------------------------------
  | Welcome to ROOT 6.36.02 https://root.cern |
  | (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jul 08 2025, 22:04:21 |
  | From tags/v6-36-02@v6-36-02 |
  | With c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

(TString) "{
  "_typename" : "TMatrixT<double>",
  "fUniqueID" : 0,
  "fBits" : 0,
  "fNrows" : 0,
  "fNcols" : 0,
  "fRowLwb" : 0,
  "fColLwb" : 0,
  "fNelems" : 0,
  "fNrowIndex" : 0,
  "fTol" : 0,
  "fElements" : []
}"[209]

```

Best regards,

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 5, 2025, 1:07pm UTC](https://root-forum.cern.ch/t/cea-46521-root-6-36-python-serialisation-of-tmatrixd-with-tbufferjson-issue/63981/2 "2025-08-05T13:07:14Z")

</div>

I guess @jonas can help

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [August 5, 2025, 3:55pm UTC](https://root-forum.cern.ch/t/cea-46521-root-6-36-python-serialisation-of-tmatrixd-with-tbufferjson-issue/63981/3 "2025-08-05T15:55:24Z")

</div>

Hi,

`TBuffer::ToJSON` has template parameter and need special signature to correctly call it in python.  
But probably you can use `TBufferJSON::ConvertToJSON()` method. It should work for TMatrixD.  
Like:

```auto
 python3 -c "import ROOT; print(ROOT.TBufferJSON.ConvertToJSON(ROOT.TMatrixD()))" 

```

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![Salomon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/salomon/32/18000_2.png) [@Salomon](https://root-forum.cern.ch/u/Salomon)\
**Post date:** [August 6, 2025, 10:53am UTC](https://root-forum.cern.ch/t/cea-46521-root-6-36-python-serialisation-of-tmatrixd-with-tbufferjson-issue/63981/4 "2025-08-06T10:53:42Z")

</div>

> [@linev](#):
>
> `python3 -c "import ROOT; print(ROOT.TBufferJSON.ConvertToJSON(ROOT.TMatrixD()))" `

Thank you very much!

Your solution works:

```bash
$ root -q
   ------------------------------------------------------------------
  | Welcome to ROOT 6.36.02 https://root.cern |
  | (c) 1995-2025, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Jul 08 2025, 22:04:21 |
  | From tags/v6-36-02@v6-36-02 |
  | With c++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

```

```bash
$ python3 -c "import ROOT; print(ROOT.TBufferJSON.ConvertToJSON(ROOT.TMatrixD()))" 
{
  "_typename" : "TMatrixT<double>",
  "fUniqueID" : 0,
  "fBits" : 0,
  "fNrows" : 0,
  "fNcols" : 0,
  "fRowLwb" : 0,
  "fColLwb" : 0,
  "fNelems" : 0,
  "fNrowIndex" : 0,
  "fTol" : 0,
  "fElements" : []
}

```

What is the difference between [`ToJSON()`](https://root.cern/doc/v636/classTBufferJSON.html#a49f3c7b200113d7009d61d75c933c398) and [`ConvertToJSON()`](https://root.cern/doc/v636/classTBufferJSON.html#a38d20878d3af12bb03c4da37f4960ad3)?

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [August 6, 2025, 11:08am UTC](https://root-forum.cern.ch/t/cea-46521-root-6-36-python-serialisation-of-tmatrixd-with-tbufferjson-issue/63981/5 "2025-08-06T11:08:48Z")

</div>

Hi,

With `ToJSON` one can use any object type - but method uses object type as template argument.  
On C++ object type detected automatically, in python such feature not always works.

With `ConvertJSON` one normally converts derived from `TObject` classes - which is a case for `TMatrixD`. And python has no problem to use it.

Regards,  
Sergey
