Home > Back-end >  how to remove the " \ " sign in the input in golang raw json
how to remove the " \ " sign in the input in golang raw json

Time:02-02

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

CodePudding user response:

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, "\\", ""))
  • Related