Report a bug
If you spot a problem with this page, click here to create a Github issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
a local clone.
asdf.transform
Mutable ASDF data structure.
The representation can be used to compute a difference between JSON object-trees.
Authors:
Ilya Yaroshenko
License:
BSL-1.0
Object-tree structure for mutable Asdf representation.
AsdfNode can be used to construct and manipulate JSON objects.
Each AsdfNode can represent either a dynamic JSON object (associative array of AsdfNode nodes) or a ASDF JSON value.
JSON arrays can be represented only as JSON values.
Children nodes.
Returns true if the node is leaf.
Construct AsdfNode recursively.
Examples:
import asdf; auto text = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`; auto root = AsdfNode(text.parseJson); assert(root["inner", "a"].data == `true`.parseJson);
Examples:
import asdf; auto text = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`; auto root = AsdfNode(text.parseJson); auto value = AsdfNode(`true`.parseJson); root["inner", "g", "u"] = value; assert(root["inner", "g", "u"].data == true);
Parameters:
AsdfNode value | default value |
char[][] keys | list of keys |
Returns:
[keys] if any and value othervise.
Examples:
import asdf; auto text = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`; auto root = AsdfNode(text.parseJson); auto value = AsdfNode(`false`.parseJson); assert(root.get(value, "inner", "a").data == true); assert(root.get(value, "inner", "f").data == false);
Serilization primitive
Examples:
import asdf; auto text = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`; auto root = AsdfNode(text.parseJson); import std.stdio; Asdf flat = cast(Asdf) root; assert(flat["inner", "a"] == true);
Examples:
import asdf; auto text = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`; auto root1 = AsdfNode(text.parseJson); auto root2= AsdfNode(text.parseJson); assert(root1 == root2); assert(root1["inner"].children.remove("b")); assert(root1 != root2);
Adds data to the object-tree recursively.
Examples:
import asdf; auto text = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`; auto addition = `{"do":"re","inner":{"a":false,"u":2}}`; auto root = AsdfNode(text.parseJson); root.add(addition.parseJson); auto result = `{"do":"re","foo":"bar","inner":{"a":false,"u":2,"b":false,"c":"32323","d":null,"e":{}}}`; assert(root == AsdfNode(result.parseJson));
Removes keys from the object-tree recursively.
Examples:
import asdf; auto text = `{"foo":"bar","inner":{"a":true,"b":false,"c":"32323","d":null,"e":{}}}`; auto rem = `{"do":null,"foo":null,"inner":{"c":null,"e":null}}`; auto root = AsdfNode(text.parseJson); root.remove(rem.parseJson); auto result = `{"inner":{"a":true,"b":false,"d":null}}`; assert(root == AsdfNode(result.parseJson));
Returns a subset of the object-tree, which is not represented in node.
If leaf represented but has different value then it will be included to return value.
Returned value has ASDF format and its leafs are set to null.
Examples:
import asdf; auto text1 = `{"inner":{"a":true,"b":false,"d":null}}`; auto text2 = `{"foo":"bar","inner":{"a":false,"b":false,"c":"32323","d":null,"e":{}}}`; auto node1 = AsdfNode(text1.parseJson); auto node2 = AsdfNode(text2.parseJson); auto diff = AsdfNode(node2.removed(node1)); assert(diff == AsdfNode(`{"foo":null,"inner":{"a":null,"c":null,"e":null}}`.parseJson));
Returns a subset of the node, which is not represented in the object-tree.
If leaf represented but has different value then it will be included to return value.
Returned value has ASDF format.
Examples:
import asdf; auto text1 = `{"foo":"bar","inner":{"a":false,"b":false,"c":"32323","d":null,"e":{}}}`; auto text2 = `{"inner":{"a":true,"b":false,"d":null}}`; auto node1 = AsdfNode(text1.parseJson); auto node2 = AsdfNode(text2.parseJson); auto diff = AsdfNode(node2.added(node1)); assert(diff == AsdfNode(`{"foo":"bar","inner":{"a":false,"c":"32323","e":{}}}`.parseJson));
Tamedia Digital, 2016
| Page generated by
Ddoc on Sat Apr 7 16:50:38 2018