Skip to content

DT Format

Peter Naydenov edited this page Feb 24, 2017 · 4 revisions

DT format is a flatten version of the standard javascript object(ST). Values in DT are always a primitives. Keys represent place of that primitives. Keys should look like a folder path ('root/sub_object/property').

What DT format looks like?

Object in DT format looks like standard flat javascript object. Object with keys and values. Differences are coming with object nestling. Example:

// Standard JS object
let movie = {
                name : 'The LEGO Batman'
              , details : {
                            director : 'Chris McKay'
                          , stars : [
                                       Will Arnett
                                     , Michael Cera
                                     , Rosario Dawson
                                   ] 
            }}

// DT format version will look like:
let movieDT = {
                  'root/name' : 'The LEGO Batman'
                , 'root/details/director' : 'Chris McKay'
                , 'root/details/stars/0' : 'Will Anett'
                , 'root/details/stars/1' : 'Michael Cera'
                , 'root/details/stars/2' : 'Rosario Dawson'
           }

All structure complexity and brackets are represented in the object keys.

Benefits of DT format

  • Creation of deep nested objects by using just strings;
  • Search in all object structure by using strings or regular expressions;
  • Fast object clone and serialization operations;
  • Changing the data structure is trivial map operation;
  • Flatten object works great with key/value stores like Redis;

Why DT is not using dot notation instead?

There are two simple reasons:

  • Dot notation in javascript represent objects,sub-objects, and properties. Using same approach for showing the keys could bring some cognitive problems: Is it an object or it's just the key? Clear separation can improve readability;
  • Source of inspiration for DT format is exactly folder-file structure and everyone know how to use it;

Representation of Different Structures

  • Object
const sample = {
                  a : 12
                , details : { 
                                'price' : 44
                              , 'discount' : 12
                            }
                };

// DT format will looks like this:
let dt = {
             'root/a': 12
           , 'root/details/price' : 44
           , 'root/details/discount' : 12
         }
  • Array
const sample = 
                [
                     'Niki'
                   , 'Alex'
                   , 'Rony'
                ]
               
// and corresponding DT: 
let dt = {
              'root/friends/0' : 'Niki'
            , 'root/friends/1' : 'Alex'
            , 'root/friends/2' : 'Rony'
         }
}