Ruby Hash Formatter

Paste a Ruby hash or array, for example from p or inspect. The formatter indents nested hashes and can align the => arrows.

Tags: beautify code format array

🚀 298,341 total conversions (646 this month)

Practice Python with coding challenges

Solve hands-on problems right in this editor: run the sample tests, submit, and get an AI code review.

All Python challenges
Easy

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

You'll learn ArithmeticReturn values
BeginnerLearning-pathVariables
Easy

Days in a Month

Return how many days a month has, including leap years.

You'll learn Calendar rulesHelper functions
BeginnerConditionsFunctionsLearning-path
Easy

Dot Product of Two Vectors

Multiply two vectors element by element and add the results: the core operation of every neuron.

You'll learn VectorsDot product
Neural networksaimachine learning
Easy

Distance Between Points

Compute the straight-line distance between two points.

You'll learn Pythagorean theoremSquare roots
BeginnerFunctionsLearning-pathmath
Easy

Average of Three

Average three whole numbers.

You'll learn ArithmeticDivision
BeginnerLearning-pathVariables
Easy

To-Do List

Keep a list of tasks: add them, mark them done, remove them and report what is still pending.

You'll learn Typed collectionsRecords
BeginnerSimulationStrings
Easy

Prime Number Check

Decide whether a number is prime.

You'll learn DivisibilityLoop optimization
BeginnerLoopsNumbersStudent-beginner
Hard

Word Break

Decide whether text can be split into dictionary words.

You'll learn Prefix DPString segmentation
AdvancedDynamic-programmingHackathonStrings
Easy

Count Pairs With a Sum

Count pairs of positions whose values add up to a target.

You'll learn Pairs of indexesAvoiding double counts
ArraysBeginnerLearning-pathNested-loops
Easy

Missing Number

Find the one number missing from 0..n.

You'll learn Arithmetic seriesSum difference trick
ArraysBeginnerStudent-beginnermath
Medium

K-th Smallest Element

Find the k-th smallest value without fully sorting.

You'll learn QuickselectPartitioning
AdvancedCompetitive-programmingSorting
Easy

Min and Max Together

Find the smallest and largest value in one pass.

You'll learn Single passMultiple return values
ArraysBeginnerFunctionsLearning-path

What is This Tool?

This free online beautifier helps you format and align arrays or hashes across popular languages like Ruby, PHP, JavaScript, and Python. It’s perfect for developers and data analysts who want clean, readable structures.

In addition to raw array/hash code, this tool also supports beautifying the output of:

  • PHP functions like print_r(), var_dump(), and var_export()
  • Python-style structures including dict, list, and complex nested objects
  • JavaScript objects and arrays
  • Output of frameworks/libraries like LangChain or custom formats like Document(...) or MyObject(...)

How to Use

  1. Paste or type your array/hash code or PHP dump output into the editor.
  2. Optionally adjust the indentation or enable value alignment.
  3. Click to format your structure.

You can download the result, copy it, or share a unique link. Sign in with Google or GitHub to save and access your beautified code later.

Understanding PHP Dump Outputs

PHP debugging functions like print_r(), var_dump(), and var_export() output structured data, but the formatting can be hard to read when deeply nested.

  • print_r(): readable format with nested Array() blocks
  • var_dump(): verbose, includes type and length info
  • var_export(): outputs valid PHP code structure

What is Document(...) or MyObject(...)?

In some Python libraries or frameworks, objects are printed using a constructor-like format such as Document(metadata={...}, page_content='...') or MyObject(...). This tool can parse and format such object lists, including any deeply nested data.

Array vs Hash (Object/Dict): What’s the Difference?

  • Array: ordered list of values (e.g. [1, 2, 3])
  • Hash/Object/Dict: key-value pairs (e.g. {"name": "Alice"})

These structures appear in many languages:

  • Ruby: [] for arrays, { key: value } for hashes
  • PHP: uses array() for both arrays and hashes
  • JavaScript: [] for arrays, { key: value } for objects
  • Python: [] for lists (arrays), { key: value } for dicts (hashes)

Examples

JavaScript Array


const nums = [1, 2, 3, 4, 5];
    

JavaScript Object


{
  "name": "Alice",
  "age": 30
}
    

Python List


["apple", "banana", "cherry"]
    

Python Dict


{
  "id": 1,
  "name": "Bob"
}
    

LangChain Document


[
  Document(
    metadata={
      "source": "/content/file.pdf",
      "coordinates": {
        "points": ((47.94, 47.29), (47.94, 74.42)),
        "system": "PixelSpace"
      }
    },
    page_content="Example text"
  )
]
    

MyObject List


[
  MyObject(
    metadata={
      "key1": "value1",
      "key2": [1, 2, 3]
    },
    content="Some content here"
  ),
  MyObject(
    metadata={
      "key1": "another",
      "key2": [4, 5]
    },
    content="Another content"
  )
]
    

Beautification Examples

Before: print_r() Output


Array
(
  [name] => Alice
  [age] => 30
  [address] => Array
    (
      [city] => Paris
      [zip] => 75001
    )
)
    

After Beautify


array(
  "name"    => "Alice",
  "age"     => 30,
  "address" => array(
    "city" => "Paris",
    "zip"  => 75001
  )
)
    

Before: Python Dict


{'a':1,'b':{'x':10,'y':20},'c':[1,2,3]}
    

After Beautify


{
  'a': 1,
  'b': {
    'x': 10,
    'y': 20
  },
  'c': [
    1,
    2,
    3
  ]
}
    

Before: JavaScript Array


const data = [1, {"a":2,"b":[3,4]}, 5];
    

After Beautify


const data = [
  1,
  {
    "a": 2,
    "b": [
      3,
      4
    ]
  },
  5
];
    

Before: Custom Object List


[MyObject(metadata={'key1': 'value1', 'key2': [1, 2, 3]}, content='Some content here'),
 MyObject(metadata={'key1': 'another', 'key2': [4, 5]}, content='Another content')]
    

After Beautify


[
  MyObject(
    metadata={
      'key1': 'value1',
      'key2': [
        1,
        2,
        3
      ]
    },
    content='Some content here'
  ),
  MyObject(
    metadata={
      'key1': 'another',
      'key2': [
        4,
        5
      ]
    },
    content='Another content'
  )
]