What is “compressed JSON”?

后端 未结 4 611
盖世英雄少女心
盖世英雄少女心 2021-01-04 02:53

I see a lot of references to \"compressed JSON\" when it comes to different serialization formats. What exactly is it? Is it just gzipped JSON or something else?

4条回答
  •  迷失自我
    2021-01-04 03:14

    Based in Paniyar's answer, we can convert a List of Objects in "compressed" Json format using C# like this:

    var JsonString = serializer.Serialize(
    new
    {
        cols = new[] { "field1", "field2", "field3"},
        items = data.Select(x => new object[] {x.field1, x.field2, x.field3})
    });
    

    I used an array of object because the fields can be int, bool, string...

    More Reduction: If the field is repeated very often and it is a string type, you can get compressed a little be more if you add a distinct list of that field... for instance, a field name job position, city, etc are excellent candidate for this. You can add a distinct list of this items and in each item change the value for a reference number. That will make your Json more lite.

提交回复
热议问题