MaterialXJSON 1.39.0
|
This is a Python package for supporting interoperability of MaterialX documents by adding support conversion to / from a JSON
representation.
The JSON
representation is lossless and is targeted at integrations which prefer to use JSON
as a data exchange format instead of XML
.
Visit the home page for For further information about this package, including links to API documentation and a Jupyter notebook with sample code that expands on the basic Usage example.
A plugin using this package is available as a sample as part of QuilitX as of this change [https://github.com/PrismPipeline/QuiltiX/commit/e34ebfec22a334d323803b6797beb8db581ebb18].
The Python package is losted on PyPi and can be installed using pip
`:
or the source repository can be cloned and the package built from the command line:
This will build a distribution folder called dist
which contains a zip file which can be installed using:
The following example shows bidirectional conversion:
XML
format is read in and written to a string in JSON
format.JSON
format is read in and written to a string in XML
format.Note that any JSON
package can be used to perform JSON
I/O. The json
package is used by the utilities provided in this package.
The materialjson
package can be loaded as follows, along with MaterialX and json packages:
A MaterialX document can be read in from an XML file as follows:
and then converted to JSON format as follows by creating a MaterialXJson
object and calling the documentToJSON
method:
The contents of the JSON object can be extracted out using the json
package as follows. (An indentation level of 2
is used to make the output more readable.)
A JSON file can be read in as follows. In this case we load the sample file included with the package:
The JSON object is then converted to a MaterialX document and written out to an XML string as follows:
The following are some caveats to be aware of when using this package: