readdictionary
Read dictionary from file.
📝Syntax
d = readdictionary(filename)
d = readdictionary(filename, Name, Value)
📥Input Arguments
Parameter Description
filename text scalar: source file name.
📤Output Arguments
Parameter Description
d scalar: dictionary object.
📄Description

d = readdictionary(filename) reads a JSON object from filename and returns it as a dictionary.

JSON object member names become string dictionary keys. Values are converted to Nelson values. JSON arrays are decoded as cell column arrays. If the JSON values have mixed types or non-scalar sizes, the dictionary value type is cell.

d = readdictionary(filename, Name, Value) customizes the read operation. Supported options are:

DictionaryNodeName and DictionarySelector are accepted as option names, but they are not supported for JSON dictionary files.

💡Examples
Read a dictionary written as JSON.
filename = [tempdir(), 'products.json'];
d = dictionary(["apple", "banana"], [1.2, 2.3]);
writedictionary(d, filename);
r = readdictionary(filename)
Read values with an explicit type.
filename = [tempdir(), 'counts.json'];
filewrite(filename, '{"a": 1, "b": 2}');
d = readdictionary(filename, 'ValueType', 'single')
🔗See Also
writedictionarydictionaryloadnh5loadmat
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub