JsonData
JsonData is a Dynamo package to provide extra functionalities when handling data, based on Newtonsoft JsonNet C# library.
The original purpose was to provide a simpler way of handling data in Dynamo. Lists work just fine, but sometimes they are just not enough. With several functionalities to filter, update, combine and group your data, this package can help to boost your Dynamo workflows.
Elements
The package is based on the use of two types objects JsonObject and JsonArray.
JsonObject
This is the core element of the package. Being a Dictionary
its underlying c# object type, JsonObjects provide several of a dictionary’s methods with the extra value of displaying them using a json structure format.
Constructors
|
|
|
ByKeysAndValues: JsonObject constructor by a given key-value pair. It accepts nested structures by providing keys divided by points as a single string. |
Methods
|
|
|
Add: Adds new attribute to the JsonObject. If given key already on the object and update set to True, value associated with the key will be updated. An error will be thrown otherwise. |
|
FilterByKeyAndValue: Filters JsonObjects which contains the given key-value pair. If value is of type string, it will test if it contains the value given. |
|
GetValueByKey: Returns the value associated with the given key from the jsonObject. |
|
JsonOptions: Options for updating JsonObjects: None, Update and Combine. |
|
Merge: Merge one JsonObject with one or multiple other JsonObjects. |
|
Remove: Remove keys from the given JsonObject. If any key doesn’t exit on the object or duplicated keys found on the input, error will be thrown. |
|
SortByKeyValue: Sorts a list of JsonObjects by the ascending order of the values associated with the given key. |
|
SortKeys: Sorts the JsonObject alphabetically by its keys. |
Properties
|
|
|
Keys: Returns keys of attributes in the JsonObject. |
|
Size: Returns the number of attributes on the JsonObject. |
|
Size: Returns values of attributes in the JsonObject. |
JsonArray
JsonArray acts more as a helper object than a key one. Due to Dynamo’s lacing properties, I soon found that the value of a JsonObject couldn´t be a list of items, so here is were JsonArray comes into play: it is a c# List
behaving as a single element, so JsonObjects can host them as a value.
Constructors
|
|
|
ByElements: JsonArray constructor by a given list of elements. |
Properties
|
|
|
Elements: Returns elements in the JsonArray object. |
|
Size: Returns the number of elements in the JsonArray object. |
Utilities
The tools provided along with the package are currently focused on handling and parsing files from and to json format.
Parse
|
|
|
CSVString: Parses a CSV formated string. It will return a list of JsonObjects. Error will be thrown if parser fails. |
|
JsonString: Parses a json formated string. It will return JsonObject, JsonArray or other match that the parser can do from the input. Error will be thrown if parser fails. |
|
JsonToCSV: Converts a list of JsonObject to CSV string format. JsonObjects must have one level only (no other JsonObject or JsonArray as values), being the keys the header of the CSV string.Parses a CSV formated string. It will return a list of JsonObjects. Error will be thrown if parser fails. |
|
JsonToXML: Converts a JsonObject to XML string format. Parses a CSV formated string. It will return a list of JsonObjects. Error will be thrown if parser fails. |
|
XMLString: Parses a xml formated string. It will return JsonObject, JsonArray or other match that the parser can do from the input. Error will be thrown if parser fails. |
Read
|
|
|
FromCSVFile: Reads and parses a CSV formated file. It will return a list of JsonObjects. Error will be thrown if parser fails. |
|
FromJsonFile: Reads and parses a json file. It will return JsonObject, JsonArray or other match that the parser can do from the input. Error will be thrown if parser fails. |
|
FromXMLFile: Reads and parses a XML file. It will return JsonObject, JsonArray or other match that the parser can do from the input. Error will be thrown if parser fails. |
Write
|
|
|
ToCSVFile: Writes a list of JsonObject to a CSV file. JsonObjects must have one level only (no other JsonObject or JsonArray as values), being the keys the header of the CSV string. |
|
ToJsonFile: Writes the JsonObject or JsonArray to a json file. |
|
ToXMLFile: Writes the JsonObject or JsonArray to a XML file. |