Search code examples
jsongoescaping

how to remove the " \ " sign in the input in golang raw json


and this is an example of its input

[
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180028\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    },
    {
        \"type\":\"Non Custom\",
        \"so_no\":\"3250109150\",
        \"material_code\":\"F100101180030\",
        \"po_no\":\"JDC/00067/02/22/2/DL\",
        \"pr_no\":\"\",
        \"gr_no\":\"\",
        \"gr_date\":\"\"
    }
]

Remove the \ sign in raw json input

And please help who can fix it


Solution

  • To solve this problem, you can pass the JSON into a string and replace every backslash like shown below:

    json := `[
        {
            \"type\":\"Non Custom\",
            \"so_no\":\"3250109150\",
            \"material_code\":\"F100101180028\",
            \"po_no\":\"JDC/00067/02/22/2/DL\",
            \"pr_no\":\"\",
            \"gr_no\":\"\",
            \"gr_date\":\"\"
        },
        {
            \"type\":\"Non Custom\",
            \"so_no\":\"3250109150\",
            \"material_code\":\"F100101180030\",
            \"po_no\":\"JDC/00067/02/22/2/DL\",
            \"pr_no\":\"\",
            \"gr_no\":\"\",
            \"gr_date\":\"\"
        }
    ]`
    fmt.Println(strings.ReplaceAll(json, "\\", ""))