# Solved Paste JSON Values on the Node Network?

Hi,

Recently learned that you can copy a node network (not just a node but a network) and paste it to a text editor, and it shows a JSON format.

So I wondering if its possible to retrieve this JSON format offdisk and load (i.e. paste it into the network) and consequently have the node network ready to go.

Performing a lot of AddChild and Connect could work but using the already tried and proven network from the JSON file is much more easier and easier to debug.

Is there a way around this?

@bentraje
I wrote the c4djson module to do what you described for ordinary c4d objects, but not for xpresso and node network(Neutron and node material). If it's impletmented, the json format maybe like this:

{
"Node Graph Root": {
"Node Identifier 1": {
"Attr1": "Value1",
"Attr2": "Value2",
...
"In Ports": {
"Port 1": {},
"Port 2": {},
...
},
"Out Ports": {
"Port 1": {},
"Port 2": {},
...
},
},
"Node Identifier 2": {...},
...
"Connections": [ (OutPort, InPort), (OutPort, InPort), ... ]
}
}


There's not a decent way for the parser to define or find the ports. And some parameters dynamicly occur when connections made. So, the sequence of node creating parameters setting and ports connecting must be carefully handled.Then too much more information is needed for node system, making things more complex.This goes against my original vision. From a certain point of view, the node system is essentially a kind of programming language, using json to serialize it seems stupid and superfluous.

C4DJSON -- a useful module to load an dump c4d objects in python dict format (similar to standard python json module).
Examples on Notion.

Thanks for the response. @iplai

your solution is definitely the ideal one and would have probably use it as a basis to create a node creation-json parser.
but at this time, I'm a bit pressed of time so I'm not any leisure to explore

I was hoping there is a load json method like hidden somewhere.
I mean the likehood that there is already an existing parser is high since you can copy and paste json already directly to the node editor, out of the box.

Hello @bentraje,

Thank you for reaching out to us. What you want to do is not possible in the Python API, and at least not trivial in the C++ API.

##### Background

What you see there when you copy and paste the nodes, is the JSON serialization data format of the maxon API. It works similar to popular abstracted data type serialization systems, as for example the attribute driven XML serialization of C#. I.e., it can serialize almost any data structure and its values, not just nodes. The closest related concept in the classic API would be Resources, although they could only be used to deserialize GUIs and did not store any values (apart from strings), i.e., just stored the structure.

Realized is this with the interface contract DescribeIo, with which data can both be serialized (written from memory to disk) and deserialized (the other way). DescribeIo is a fairly low-level concept of the maxon C++ API. The more high-level concept is DataDescriptionInterface. While some parts of this have been wrapped for Python, it has not been done to the extent required here. Added to this is that neither GraphModelInterface nor GraphNode are such DataDescriptionInterface and are instead serialized over NodeTemplateInterface. So, in the end, you cannot instantiate a GraphNode directly from a JSON file, even in C++. NodeTemplateInterface has not been wrapped for Python, but I showed in the Asset API C++ docs how to create and load node assets. The loading part can be done in Python, the creating part not, due to some methods not being wrapped. But this all works over the serialized data stored in asset databases, not the raw JSON, but what a node template effectively stores is such JSON data.

##### What you can do

Not much, unfortunately, direct node JSON serialization and deserialization is neither supported in the public C++ nor public Python API. You can of course try to start deserializing data yourself with the json module of Python, but we cannot provide any help with that.

The most realistic thing would be a request for us to support NodeTemplateInterface in Python, so that you can load and store node setups programatically in a dummy or proper user database.

Cheers,
Ferdinand

MAXON SDK Specialist
developers.maxon.net

Thanks for the confirmation.
No worries found a hack way to implement through python keyboard simulation

Maybe if I have extra time near the end I can use @iplai library for node json creation. Or maybe the C4D team has already implement one by then hehe

@bentraje
This is my trial:

import c4d

with open(r"Path\to\your\file.json") as f: