【the waiter】announcement:

Json to proto
9753  |   |   |  27

feature introduction

  1. Support parsing nested json strings and parsing nested objects according to recursion
  2. Parsing array json string is supported. The first json string in the array will be parsed.
  3. Check whether the format of the json string is correct and the location of the output error

example

parsing nested json strings

{
    "name": "test",
    "age": 10,
    "addr": "Sichuan Chengdu",
    "cls_info": [
        {
            "name": "basketball class",
            "teacher": "Mr. Zhang"
        },
        {
            "name": "Art Class",
            "teacher": "Miss Li"
        }
    ]
}

After treatment

message GenerateObj {
    string name = 1;
    int32 age = 2;
    string addr = 3;
    repeated ClsInfo cls_info = 4;
}

message ClsInfo {
    string name = 1;
    string teacher = 2;
}

parsing array json strings directly

[
    {
        "name": "test",
        "age": 10,
        "addr": "Sichuan Chengdu",
        "cls_info": [
            {
                "name": "basketball class",
                "teacher": "Mr. Zhang"
            },
            {
                "name": "Art Class",
                "teacher": "Miss Li"
            }
        ]
    }
    {
        "name": "test2",
        "age": 10,
        "addr": "Sichuan Chengdu",
        "cls_info": [
            {
                "name": "basketball class",
                "teacher": "Mr. Zhang"
            },
            {
                "name": "Art Class",
                "teacher": "Miss Li"
            }
        ]
    }
]

After treatment

message GenerateObj {
    string name = 1;
    int32 age = 2;
    string addr = 3;
    repeated ClsInfo cls_info = 4;
}

message ClsInfo {
    string name = 1;
    string teacher = 2;
}