Understanding data transformations between basic entities
Transforms allow you to convert data between different formats in Fractal Platform. Think of it like translating between languages - the same information can be expressed in different ways depending on what you need to do with it.
Fractal Platform works with five basic data formats, each optimized for different tasks:
| Format | Description | Best For |
|---|---|---|
| JSON | Text representation of data | APIs, configuration files, human-readable data exchange |
| Objects | C# classes and objects | Application logic, type-safe code, business rules |
| AttrList | Flat list of attribute paths and values | LINQ queries, attribute manipulation, granular control |
| Storage | Database-level container for documents | Persisting data, database operations, large datasets |
| Collection | Storage with dimensions (metadata, validation, etc.) | Forms, validation rules, complex data structures |
You can transform between any two formats. Here's how they connect:
All formats are bidirectionally convertible
JSON (from API) → Objects (validate) → Storage (save to DB)
Storage (from DB) → Collection (add validation) → Form Display
Storage (from DB) → AttrList (LINQ operations) → Objects (business logic)
Each format has specific advantages:
This document describes transformations between basic hierarchy entities in Fractal Platform. There are 5 basic entities that can describe a Document or list of Documents.
Text document that describes a hierarchy object.
{ "Name": "Bob", "Age": 21, "IsManager": false }
List of C# objects in the Application.
var objects = new[] { new { Name = "Bob", Age = 21, IsManager = false }, new { Name = "Tim", Age = 25, IsManager = true } };
List of attributes in the Document. Usually used when you want to do LINQ queries among Document attributes.
var docID = 1U; var attrs = new AttrList { new KeyValuePair<AttrPath, AttrValue>(new AttrPath("Name", docID), new AttrValue("Bob")), new KeyValuePair<AttrPath, AttrValue>(new AttrPath("Age", docID), new AttrValue(21)), new KeyValuePair<AttrPath, AttrValue>(new AttrPath("IsManager", docID), new AttrValue(false)) };
\ for nested objects and \[0] for arrays.
// JSON: {"Name":"Bob","Params":{"Age":21},"Arr":[1,2]} var attrs = new AttrList { new KeyValuePair(new AttrPath("Name", docID), new AttrValue("Bob")), new KeyValuePair(new AttrPath(@"Params\Age", docID), new AttrValue(21)), new KeyValuePair(new AttrPath(@"Arr\[0]", docID), new AttrValue(1)), new KeyValuePair(new AttrPath(@"Arr\[1]", docID), new AttrValue(2)) };
Container that contains list of Documents on Database level.
// Create standalone Storage var storage = new BUFStorage("Document"); storage.Init(); // Read Storage from a Database var storage = DocsOf("Users").ToStorage();
Container that contains list of Storages. Main Storage in the Collection is called Document. Other Storages around Document are called Dimension.
// Create standalone empty Collection var collection = new Collection("MyCollection"); // Create collection based on a Storage var storage = new BUFStorage("Document"); storage.Init(); var collection = new Collection(storage); // Read collection from Database var collection = DocsOf("Users").ToCollection();
Deserialize JSON to C# objects.
public class User { public string Name { get; set; } public int Age { get; set; } public bool IsManager { get; set; } } var json = @"{ 'Name': 'Bob', 'Age': 21, 'IsManager': false }"; var user = JsonConvert.DeserializeObject<User>(json);
var json = @"{'Name': 'Bob','Age': 21,'IsManager': false}"; var attrs = AttrList.FromJson(Context.SystemContext, json);
var json = @"{'Name': 'Bob','Age': 21,'IsManager': false}"; var storage = new BUFStorage(); storage.Init(); storage.FromJson(Context.SystemContext, json, Constants.FIRST_DOC_ID);
var json = @"{'Name': 'Bob','Age': 21,'IsManager': false}"; var collection = Collection.FromJson(Context.SystemContext, json);
var user = new User { Name = "Bob", Age = 21, IsManager = false }; var json = user.ToJson();
var user = new User { Name = "Bob", Age = 21, IsManager = false }; var attrs = user.ToAttrList(Context.SystemContext, Constants.FIRST_DOC_ID);
var user = new User { Name = "Bob", Age = 21, IsManager = false }; var storage = user.ToStorage(Context.SystemContext, Constants.FIRST_DOC_ID);
var user = new User { Name = "Bob", Age = 21, IsManager = false }; var collection = user.ToCollection(Context.SystemContext, Constants.FIRST_DOC_ID);
var docID = 1U; var attrs = new AttrList { new KeyValuePair(new AttrPath("Name", docID), new AttrValue("Bob")), new KeyValuePair(new AttrPath("Age", docID), new AttrValue(21)) }; var json = attrs.ToJson(Context.SystemContext, Constants.FIRST_DOC_ID);
var attrs = /* AttrList */; var user = attrs.ToObject<User>();
var attrs = /* AttrList */; var storage = attrs.ToStorage();
var attrs = /* AttrList */; var collection = attrs.ToCollection();
var storage = new BUFStorage(); storage.Init(); var json = storage.ToJson(Context.SystemContext);
var storage = new BUFStorage(); storage.Init(); var users = storage.GetAll(Context.SystemContext) .Select<User>();
var storage = new BUFStorage(); storage.Init(); var attrs = storage.ToAttrList();
var storage = new BUFStorage(); storage.Init(); var collection = storage.ToCollection();
var collection = new Collection("Document"); var json = collection.ToJson(Context.SystemContext);
var collection = new Collection("Document"); var users = collection.GetAll(Context.SystemContext) .Select<User>();
var collection = new Collection("Document"); var attrs = collection.ToAttrList();
var collection = new Collection("Document"); var storage = collection.GetStorage(DimensionType.Document);
// Open form based on Json Collection.FromJson(context, "{'Name':'Bob','Age':21}") .OpenForm(context);
// Open form based on Json + set Dimension Collection.FromJson(context, "{'Name':'Bob','Age':21}") .SetDimension(context, DimensionType.Validation, "{'Age':{'MinValue':18,'MaxValue':120}}") .OpenForm(context);
// Open form based on Json + process attrs by LINQ Collection.FromJson(context, "{'Arr':[1,2,3,4,5]}") .ToAttrList() .Skip(2) // skip 1,2 attributes .ToCollection(context) .OpenForm(context);
// Open form based on Database + convert to attr list + update + open DocsWhere("Numbers", new { Number = 3 }) .ToCollection() .ToAttrList() .Select(x => new { Square = x.Value.GetUIntValue() * x.Value.GetUIntValue() }) // transform json from {'Number':3} to {'Square':9} .ToCollection(context) .OpenForm(context);
// Open form based on C# object var user = new { Name = "Bob", Age = 21 }; user.ToCollection(context, Constants.FIRST_DOC_ID) .OpenForm(context);
// Open form based on C# objects var users = new[] { new { Name = "Bob", Age = 21 }, new { Name = "Tim", Age = 20 } }; users.ToCollection(context, Constants.FIRST_DOC_ID) .OpenForm(context);
// Open form based on C# objects + filter var users = new[] { new { Name = "Bob", Age = 21 }, new { Name = "Tim", Age = 20 } }; users.ToCollection(context) .GetWhere(context, "{'Age':21}") .OpenForm();