Skip to content

Package Content

alvpickmans edited this page Feb 7, 2018 · 3 revisions

The package contains simple but powerful methods to create your custom json structure by providing its keys and values, or if you prefer import the content or an external file (either json, XML or CSV formats!) and use it right away on Dynamo.


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 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 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 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 GetValueByKey: Returns the value associated with the given key from the jsonObject.
JsonOptions JsonOptions: Options for updating JsonObjects: None, Update and Combine.
Merge Merge: Merge one JsonObject with one or multiple other JsonObjects.
Remove 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 SortByKeyValue: Sorts a list of JsonObjects by the ascending order of the values associated with the given key.
SortKeys SortKeys: Sorts the JsonObject alphabetically by its keys.

Properties

        
Keys Keys: Returns keys of attributes in the JsonObject.
JsonObjectSize Size: Returns the number of attributes on the JsonObject.
Values 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 ByElements: JsonArray constructor by a given list of elements.

Properties

        
Elements Elements: Returns elements in the JsonArray object.
JsonObjectSize 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 CSVString: Parses a CSV formated string. It will return a list of JsonObjects. Error will be thrown if parser fails.
JsonString 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 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.
JsonToXML 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 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 FromCSVFile: Reads and parses a CSV formated file. It will return a list of JsonObjects. Error will be thrown if parser fails.
FromJsonFile 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 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 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 ToJsonFile: Writes the JsonObject or JsonArray to a json file.
ToXMLFile ToXMLFile: Writes the JsonObject or JsonArray to a XML file.