Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

Possible Duplicate:
Pretty-Printing JSON with PHP Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (PHP 5.2.x) to encode an array into JSON output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability, so I'd like to add line breaks in and "pretty print" the JSON output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

Possible Duplicate:
Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (PHP 5.2.x) to encode an array into JSON output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability, so I'd like to add line breaks in and "pretty print" the JSON output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

Possible Duplicate:
Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (PHP 5.2.x) to encode an array into JSON output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability, so I'd like to add line breaks in and "pretty print" the JSON output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

Capitalization, formatted function names as code
Source Link
Don't Panic
  • 41.9k
  • 11
  • 70
  • 87

Possible Duplicate:
Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encodejson_encode (phpPHP 5.2.x) to encode an array into jsonJSON output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability. So, so I'd like to add line breaks in and "pretty print" the jsonJSON output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encodejson_encode at all and just write the file contents manually and add in my own line breaks for each line. Thanks.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

Possible Duplicate:
Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (php 5.2.x) to encode an array into json output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability. So I'd like to add line breaks in and "pretty print" the json output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line. Thanks.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

Possible Duplicate:
Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (PHP 5.2.x) to encode an array into JSON output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability, so I'd like to add line breaks in and "pretty print" the JSON output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

insert duplicate link
Source Link

Possible Duplicate:
Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (php 5.2.x) to encode an array into json output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability. So I'd like to add line breaks in and "pretty print" the json output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line. Thanks.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (php 5.2.x) to encode an array into json output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability. So I'd like to add line breaks in and "pretty print" the json output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line. Thanks.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

Possible Duplicate:
Pretty-Printing JSON with PHP

I'm working on a script that creates a JSON file. Right now I'm just using json_encode (php 5.2.x) to encode an array into json output. Then I print the returned value to a file and save it. Problem is that the client wants to be able to open these JSON files for readability. So I'd like to add line breaks in and "pretty print" the json output. Any ideas on how to do this? My only other alternative that I can see is to not use json_encode at all and just write the file contents manually and add in my own line breaks for each line. Thanks.

Here's what I get:

{"product_name":"prod1","val1":1,"val2":8}

Here's what I want:

{
 "product_name":"prod1",
 "val1":1,
 "val2":8
}

I suppose I could also just replace every comma with a command followed by a \n, and same for the brackets... Thoughts?

Post Closed as "exact duplicate" by Peter O., code_burgar, shellter, mccannf, CassOnMars
Source Link
Brian
  • 7.2k
  • 12
  • 56
  • 86
Loading
lang-php

AltStyle によって変換されたページ (->オリジナル) /