Si vous trouvez que l' pretty_generateoption intégrée à la bibliothèque JSON de Ruby n'est pas assez "jolie", je recommande mon propre bijou NeatJSON pour votre mise en forme.
Pour l'utiliser:
gem install neatjson
puis utiliser
JSON.neat_generate
au lieu de
JSON.pretty_generate
Comme Ruby, ppil gardera les objets et les tableaux sur une seule ligne lorsqu'ils s'adapteront, mais en enroulera en plusieurs si nécessaire. Par exemple:
{
  "navigation.createroute.poi":[
    {"text":"Lay in a course to the Hilton","params":{"poi":"Hilton"}},
    {"text":"Take me to the airport","params":{"poi":"airport"}},
    {"text":"Let's go to IHOP","params":{"poi":"IHOP"}},
    {"text":"Show me how to get to The Med","params":{"poi":"The Med"}},
    {"text":"Create a route to Arby's","params":{"poi":"Arby's"}},
    {
      "text":"Go to the Hilton by the Airport",
      "params":{"poi":"Hilton","location":"Airport"}
    },
    {
      "text":"Take me to the Fry's in Fresno",
      "params":{"poi":"Fry's","location":"Fresno"}
    }
  ],
  "navigation.eta":[
    {"text":"When will we get there?"},
    {"text":"When will I arrive?"},
    {"text":"What time will I get to the destination?"},
    {"text":"What time will I reach the destination?"},
    {"text":"What time will it be when I arrive?"}
  ]
}
Il prend également en charge une variété d' options de formatage pour personnaliser davantage votre sortie. Par exemple, combien d'espaces avant / après deux-points? Avant / après des virgules? À l'intérieur des supports de tableaux et d'objets? Voulez-vous trier les clés de votre objet? Voulez-vous que les deux points soient alignés?