0

I encode array to json and get

{"payment_providers":[{"name":"ccsave","revenue":[{"date":"2013-03-18","sales":"51.00","items":"2","median_item_price":"20.50"}]},{"name":"checkmo","revenue":[{"date":"2013-03-18","sales":"79.00","items":"5","median_item_price":"8.00"}]},...

But I need:

{
    "payment_providers":[
       {"name":"ccsave",
        "revenue":[
            {"date":"2013-03-18","sales":"51.00","items":"2","median_item_price":"20.50"}
         ]
        },
        {"name":"checkmo","revenue":[
           {"date":"2013-03-18","sales":"79.00","items":"5","median_item_price":"8.00"}
         ]
        }, ...

How can I get Json looks pretty?

Alex
  • 468
  • 1
  • 9
  • 19
  • Possible duplicate http://stackoverflow.com/questions/4810841/json-pretty-print-using-javascript http://stackoverflow.com/questions/3515523/javascript-how-to-generate-formatted-easy-to-read-json-straight-from-an-object – bluszcz Mar 19 '13 at 09:30
  • I'm looking for the way to do it in PHP ;) – Alex Mar 19 '13 at 09:36

1 Answers1

1

There is a PHP function json-encode, check documentation here: http://php.net/manual/en/function.json-encode.php

and also check similar question here: Pretty-Printing JSON with PHP

Community
  • 1
  • 1
bluszcz
  • 4,054
  • 4
  • 33
  • 52