-
Notifications
You must be signed in to change notification settings - Fork 2
Element Parameters by Category
This example shows a method to retrieve all instance parameters from all elements of a given category, and save them into a json file. This goes away from the common use of excel or csv files, giving a more customizable way of structuring your data and output. It also shows how the nesting capabilities in action!
After retrieving all elements of the selected category and their parameters, a JsonObject is created for each set of parameters.
As shown on the image, instead of just using their names as keys, their parameter group is concatenated to produce a more organized json structure. Regarding values, any null
value is replaced by an empty string to avoid the constructor method to throw an error.
JsonOptions
give flexibility when handling duplicated keys. By default the node uses JsonOption.None
, so if a key already exists it throws an error. In this example, parameters 'Category' and 'Level' exist twice. By using JsonOption.Combine
their values are combined into a JsonArray and kept under the same key.
Next step is to keep the relation of which parameters belong to which element. In this example, another jsonObject is created with two properties: id
which holds the element's id and parameters
, being its value the parameter's jsonObject created on the previous step.
Lastly we are saving the data to a json file. The list of JsonObjects needs to be wrapped into a JsonArray. Otherwise the file will be written for each element on the list and therefore only the last jsonObject of the list will be kept on the file.
In this example, I chose to use the category's name as the file name, so by only changing the category another file will be created.
Download the dataset.
Once you have your json file, a good online platform for view and edit it is JSON Editor Online. Just open your file or copy the content and you´ll be able to re-order by draggin and dropping, searching and even save and share it online!
Check the saved example of the Rooms.json
file that can be found on the dataset.