How to remove all spaces from a Json string

Possible duplicate:
Effectively removing all spaces from a string
Change indented JSON string in .NET

I have a line like this:

{"languages" : [{"fluency": 4, "id": 15}], "address" : {"city_id" : 8341, "city_name" : "My city"}, "about" : null, "birthday" : "1988-03-18", "email" : " email@a.com ", "id" : 3, "income" : 4} 

I would like to have a compact / mini line like this:

 {"languages":[{"fluency":4,"id":15}],"address":{"city_id":8341,"city_name":"My city"},"about":null,"birthday":"1988-03-18","email":" email@a.com ","id":3,"income":4} 

Note:

  • I use the built-in System.Json to do serialization in my application. I get a string representation of a JsonValue object using the ToString () method, but it looks like I have no control over the format of the output string.
  • I would like to use a helper method to β€œminimize” the JSON string. I do not want to include another third-party Json library in the project.
  • I use complex JSON data structures (including nested objects / arrays)
  • I use Mono, not .NET.
+6
source share

All Articles