Align Hash/Array

Align items in nested Hash/Array for more readable, proper indentation

Tags: beautify code

Introduction

This is an online beautifier which help to beautify, align items in nested an array or a hash to nice, organized structure.

How to use this tool?

You can input/paste your hash/array code directly into the editor. Modify the indent size you want. You can also check the "Value Aligned" to align values in a same vertical line.

After beautifying/formatting your hash/array code, you can download or save/share the result. It will create a link for you to share with others. You can also sign-in using Google/GitHub to save results into your account.

What is the difference between an array and a hash?

An array is initially fixed number of memory locations. At each location it should store a predetermined type (e.g. an integer). It may or may not have repeated values.

Hash, on the other hand, is implemented as a set. It is based on an array. The position of an item in an array is given by a hash function. A hash should not contain duplicates. If duplicates happen this is called a collision and there are a number of strategies to resolve this (e.g. chain duplicates, rehash and so on).

Array in Ruby

      
days =  ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
arr = [1, 2, 3, 4, 5, 6]
      
    

Hash in Ruby

      
{
  :one  => "eins",
  :two  => "zwei",
  :three=> "drei"
}
      
    

Examples

Unbeautified (Hash in PHP):

      
array(
  "Product ID" => 10440, "SKU" => "KOI-721",
  "Name" => "Basic Beauty Off-The-Shoulder Dress",
  "Product URL" => "https://www.domain.com/product/koi-721",
  "Price" => 52, "Retail Price" => 78,
  "Thumbnail URL" => "https://www.domain.com/images/koi-721_600x600.png",
  "Search Keywords" => "lorem, ipsum, dolor, ...",
  "Description" => "Sociosqu facilisis duis ...",
  "Color Swatches" => array(array("color" => "Rosewood","family" => "Red","price" => 42), array("color" => "Thyme Green","family" => "Green","price" => 59.99)),
  "Date Created" => "2018-03-03 17:38:50"
)
      
    

After beautified (Hash in PHP):

      
array(
  "Product ID"     => 10440,
  "SKU"            => "KOI-721",
  "Name"           => "Basic Beauty Off-The-Shoulder Dress",
  "Product URL"    => "https://www.domain.com/product/koi-721",
  "Price"          => 52,
  "Retail Price"   => 78,
  "Thumbnail URL"  => "https://www.domain.com/images/koi-721_600x600.png",
  "Search Keywords"=> "lorem, ipsum, dolor, ...",
  "Description"    => "Sociosqu facilisis duis ...",
  "Color Swatches" => array(
    array(
      "color" => "Rosewood",
      "family"=> "Red",
      "price" => 42
    ),
    array(
      "color" => "Thyme Green",
      "family"=> "Green",
      "price" => 59.99
    )
  ),
  "Date Created"   => "2018-03-03 17:38:50"
)