Align Hash/Array

Align items in nested Hashes/Arrays for more readable and properly indented code

Tags: beautify code

Introduction

This online beautifier is here to help you format and organize nested arrays or hashes into a clean, well-structured layout. It’s perfect for anyone looking to make their data more readable and easier to work with.

How to Use This Tool

Using the tool is easy! Simply paste your hash or array code directly into the editor. You can adjust the indent size to suit your preference. If you want values to align vertically, check the "Value Aligned" option for a neatly organized result.

Once your code is beautified, you can download the formatted result or save and share it with others using a unique link. If you sign in with Google or GitHub, you can even save your results to your account for future use.

What’s the Difference Between an Array and a Hash?

An array is a collection of elements stored in a fixed number of memory locations, where each location holds a specific type of data (like integers). Arrays can have repeated values and are typically indexed by position.

A hash, on the other hand, organizes data as key-value pairs. It uses a hash function to determine the position of each item in an underlying array. Unlike arrays, hashes don't allow duplicate keys. If duplicates occur, it’s called a collision, and there are strategies to handle it, like chaining or rehashing.

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"
)