Closed almas1992 closed 3 years ago
I have a json string like
{ "data": [ { "name": "Product P4", "productId": "1bb3", "vendorId": "10de" }, { "name": "Product P4", "productId": "1cc3", "vendorId": "20de" }, { "name": "Product P4", "productId": "1dd3", "vendorId": "30de" } ] }
and path syntax data.#.{name,value:{productId,vendorId}} wil get data
data.#.{name,value:{productId,vendorId}}
[ { "name": "Product P4", "value": { "productId": "1bb3", "vendorId": "10de" } }, { "name": "Product P4", "value": { "productId": "1cc3", "vendorId": "20de" } }, { "name": "Product P4", "value": { "productId": "1dd3", "vendorId": "30de" } } ]
but I want to get data like this
[ { "name": "Product P4", "value": "{\"productId\":\"1bb3\",\"vendorId\":\"10de\"}" }, { "name": "Product P4", "value": "{\"productId\":\"1cc3\",\"vendorId\":\"20de\"}" }, { "name": "Product P4", "value": "{\"productId\":\"1dd3\",\"vendorId\":\"30de\"}" } ]
so I did add the modifier
gjson.AddModifier("string", func(josn, arg string) string { return strconv.Quote(josn) })
and get path syntax data.#.{name,value:{productId,vendorId}.@string} . However, after the gojson.tostr method, it looks like this
data.#.{name,value:{productId,vendorId}.@string}
[ { "name": "Product P4", "value": "{\"productId\":\"1bb3\",\"vendorId\":\"10de\"} }, { "name": "Product P4", "value": "{\"productId\":\"1cc3\",\"vendorId\":\"20de\"} }, { "name": "Product P4", "value": "{\"productId\":\"1dd3\",\"vendorId\":\"30de\"} } ]
Why value lost the last double quotes?
You found a bug. Thanks for reporting. I pushed a fix.
I have a json string like
and path syntax
data.#.{name,value:{productId,vendorId}}
wil get databut I want to get data like this
so I did add the modifier
and get path syntax
data.#.{name,value:{productId,vendorId}.@string}
. However, after the gojson.tostr method, it looks like thisWhy value lost the last double quotes?