Formattatore di Array

Abbellisci e allinea gli elementi in Hash/Array annidati provenienti da funzioni di dump di JavaScript, Python, Ruby e PHP (print_r, var_dump, var_export) per ottenere un codice più leggibile e correttamente indentato.

Tag: abbellire il codice formatta array

🚀 182,943 conversioni totali (503 questo mese)

Cos'è Questo Strumento?

Questo strumento online gratuito ti aiuta a formattare e allineare array o hash in linguaggi popolari come Ruby, PHP, JavaScript e Python. È perfetto per sviluppatori e analisti di dati che desiderano strutture pulite e leggibili.

Oltre al codice grezzo di array/hash, questo strumento supporta anche l'abbellimento dell'output di:

  • Funzioni PHP come print_r(), var_dump() e var_export()
  • Strutture in stile Python inclusi dict, list e oggetti complessi annidati
  • Oggetti e array JavaScript
  • Output di framework/librerie come LangChain o formati personalizzati come Document(...) o MyObject(...)

Come Usare

  1. Incolla o digita il tuo codice di array/hash o l'output di dump PHP nell'editor.
  2. Opzionalmente regola l'indentazione o abilita l'allineamento dei valori.
  3. Clicca su per formattare la tua struttura.

Puoi scaricare il risultato, copiarlo o condividere un link unico. Accedi con Google o GitHub per salvare e accedere al tuo codice abbellito in seguito.

Comprendere gli Output di Dump PHP

Le funzioni di debug PHP come print_r(), var_dump() e var_export() producono dati strutturati, ma la formattazione può essere difficile da leggere quando è profondamente annidata.

  • print_r(): formato leggibile con blocchi Array() annidati
  • var_dump(): dettagliato, include informazioni su tipo e lunghezza
  • var_export(): produce una struttura di codice PHP valida

Cos'è Document(...) o MyObject(...)?

In alcune librerie o framework Python, gli oggetti vengono stampati utilizzando un formato simile a un costruttore come Document(metadata={...}, page_content='...') o MyObject(...). Questo strumento può analizzare e formattare tali elenchi di oggetti, inclusi eventuali dati annidati in profondità.

Array vs Hash (Object/Dict): Qual è la Differenza?

  • Array: elenco ordinato di valori (es. [1, 2, 3])
  • Hash/Object/Dict: coppie chiave-valore (es. {"name": "Alice"})

Queste strutture appaiono in molti linguaggi:

  • Ruby: [] per gli array, { key: value } per gli hash
  • PHP: usa array() sia per gli array che per gli hash
  • JavaScript: [] per gli array, { key: value } per gli oggetti
  • Python: [] per le liste (array), { key: value } per i dict (hash)

Esempi

Array JavaScript


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

Oggetto JavaScript


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

Lista Python


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

Dict Python


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

Documento LangChain


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

Elenco MyObject


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

Esempi di Abbellimento

Prima: Output print_r()


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

Dopo Abbellimento


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

Prima: Dict Python


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

Dopo Abbellimento


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

Prima: Array JavaScript


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

Dopo Abbellimento


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

Prima: Elenco Oggetti Personalizzati


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

Dopo Abbellimento


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