PDP JSON Layouting

Basic Structure of JSON Layout

We'll refer the following structure as a node. A node is an equivalent of HTML Node (e.g, <div>, <span> ..)

{
  "type"  : "...",
  "value" : "...",
  "attr"  : {},
  "children": [
     {}
   ]
}

type, value, attr, children.. are node attributes, where,

Apart from the above attributes, node type column has special attributes,

NOTE


Analogy between JSON Node and HTML node

Consider the following simpe HTML markup

<div id="title" data-catalog-sku="SM-S3-NEO-I9300">
</div>

Lets see the JSON equivalent of following:

  1. Create a JSON with type as html_tag and value as div
    {
    "type": "html_tag",
    "value": "div"
    }
  2. Lets add attribute to the node, HTML attributes of a tag can be specified in attr attribute of the node

    {
    "type" : "html_tag",
    "value": "div",
    "attr" : {
     "id" : "title",
     "data-catalog-sku":"SM-S3-NEO-I9300"
    }
    }

    In the above example to get a <span> instead of <div> we just need to replace "value": "div" with "value": "span", similarly for any html tag. Consider a complex html markup,

    <div class=" row">
    <div class="col-md-5 col-sm-5">
    </div>
    <div class="col-md-7 col-sm-7">
    </div>
    </div>

    Lets create the JSON equivalent of the above HTML,

  3. The below node makes up for a row

    {
    "type": "row"
    }
  4. The below node makes up for a 5 column
    {
    "type": "column",
    "width": 5
    }
  5. The below node makes up for a 7 column
    {
    "type": "column",
    "width": 7
    }
  6. All we have to do is to make 5-column and 7-column node as a children of row. The final JSON will look like
    {
    "type": "row",
    "children": [
     {
       "type": "column",
       "width": 5
     },
     {
       "type": "column",
       "width": 7
     }
    ]
    }
  7. What if we needed to add classes for breakpoint like below
    <div class=" row">
    <div class="col-md-5 col-sm-6 col-xs-6">
    </div>
    <div class="col-md-7 col-sm-6 col-xs-6">
    </div>
    </div>
    Simple, pass breakpoint widths to width as,
    {
    "type": "column",
    "width": {
     "large" : 5,
     "medium": 6,
     "small" : 6
    }
    }
    The equivalent JSON with column breakpoint widths is,
    {
    "type": "row",
    "children": [
     {
       "type": "column",
       "width": {
         "large" : 5,
         "medium": 6,
         "small" : 6
       }
     },
     {
       "type": "column",
       "width": {
         "large" : 7,
         "medium": 6,
         "small" : 6
       }
     }
    ]
    }

    NOTE

    • The type of children is always Array []
    • In JSON layout,
      • large corresponds to md
      • medium corresponds to sm
      • small corresponds to xs

Basic Structure of PDP

{
  "type": "root",
  "value":"pdp",
  "children": [
    {}
   ]
}

A Demo PDP

{
  "type": "root",
  "value": "pdp",
  "children": [
    {
      "type": "row",
      "children": [
        {
      "type": "column",
          "width": {
            "large": 6,
            "small": 12,
            "medium": 6
          },
          "visible": ["large"],
          "variations": {"push": 3},
          "children": [
            {
              "type": "block",
              "value": "pdp_breadcrumbs"
            }
          ]
        }
      ]
    },
    {
      "type": "row",
      "children": [
        {
          "type": "column",
          "width": 5,
          "children": [
            {
              "type": "row",
              "children": [
                {
                  "type": "column",
          "width": 10,
                  "children": [
                    {
                      "type": "block",
                      "value": "medium_image"
                    }
                  ]
                },
                {
                  "type": "column",
                  "width": 2,
                  "children": [
                    {
                      "type": "block",
                      "value": "catalog_images_thumb_nails"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "type": "column",
          "width": 7
        }
      ]
    },
    {
      "type": "row",
      "children": [
        {
          "type": "column",
          "width": 8
        },
        {
          "type": "column",
          "width": 4
        }
      ]
    }
  ]
}

List of Availabe Blocks