JSON Writer

JSON (JavaScript Object Notation) is a lightweight data interchange format that’s easy for humans to read and write, and easy for machines to parse and generate. It is commonly used to transmit data between a server and web application as text.

flamapy relies on file extensions to identify which transformation is required. If you are not an expert we recommend to specify the correct extension for this file type. The file extension for this file is .json

Arithmetic, aggregate and string constraints cannot be written in this format: by default the writer raises a FlamaException for a model that has them, and with boolean_only=True it writes the Boolean part of the model and warns about the constraints left out. The UVL writer keeps every constraint.


Code Examples

from flamapy.core.discover import DiscoverMetamodels
# Initiallize the dicover metamodel
dm = DiscoverMetamodels()
# Get the fm metamodel representation using the transformation 
# required to get to the fm metamodel
# the transformation is identified by file extension 
feature_model = dm.use_transformation_t2m("path/to/feature/model",'fm') 
# write to file
dm.use_transformation_m2t(feature_model,'path/to/feature/model.json')

# Or call the writer directly, keeping only the Boolean part of a model with other constraints
from flamapy.metamodels.fm_metamodel.transformations import JSONWriter
JSONWriter('path/to/feature/model.json', feature_model, boolean_only=True).transform()