This question already has answers here:
How to unmarshal an escaped JSON string
(6 answers)
Closed 9 months ago.
I use gin web framework and this is data in redis
[
{
"Score": 12,
"Member": "{"empname":"DDDDDDDD","empid":20}"
},
{
"Score": 5,
"Member": "{"empname":"Dixya Lhyaho","empid":10}"
}
]
after fetch from redis , why return like this
[
{
"Score": 12,
"Member": "{\"empname\":\"DDDDDDDD\",\"empid\":20}"
},
{
"Score": 5,
"Member": "{\"empname\":\"Dixya Lhyaho\",\"empid\":10}"
}
]
How to remove backslash in json (member only) ?
https://go.dev/play/p/QtaapMgfjtn
done.
Strongly recommend you to use json.NewDecoder() and then convert your struct by using the Decode() method. This is much more faster than Unmarshal.
You can check on detail the json documentation that Garr left you as a comment.
Anyway, how are you converting this struct to json? So we can help you better
Related
The graphql endpoint return the following invalid json response:
[
"{\"data\":{\"findById\":{\"lastName\":\"Doe\",\"firstName\":\"John\",\"gender\":\"MALE\"}}}"
]
The correct one should be:
{
"data": {
"findById": {
"lastName": "Doe",
"firstName": "John",
"gender": "MALE"
}
}
}
I created a github repo and raised an issue at https://github.com/micronaut-projects/micronaut-aws/issues/392 11 days ago, so far no one response, hence I post the question here.
Anyone face similar issue?
Thanks in advance for your helpful response.
TS-0004 Table 7.5.2-2 states that the R/6 (retrieve child-resource-references) call (?fu=1&rcn=6) should return an m2m:resourceRefList. Is this correct? At least two open-source implementations i have seen return m2m:URIList for this query.
Is there anywhere listed examples that show a more complete list of responses for combinations of query parameters?
You are right. fu=1 (discovery request) and rcn=6 should return a m2m:resourceRefList. Such as:
{
"m2m:ch": [
{
"nm": "aResource",
"typ": 99,
"val": "cse-in/aResource"
},
{
"nm": "anotherResource",
"typ": 99,
"val": "cse-in/anotherResource"
}
]
}
There are a couple of examples in the developer guides: https://www.onem2m.org/developer-guides
This question already has answers here:
Unmarshal JSON with some known, and some unknown field names
(8 answers)
Closed 5 years ago.
I am new to golang and trying to parse some response from a web service, and the response looks like:
[
{
"Data": {
"KeyA": 1,
"KeyB": 2
},
"Type": 0
},
{
"Data": {
"KeyX": "ValueX",
"KeyY": 999
},
"Type": 1
},
{
"Data": {
"Val": 123,
"Id": "999",
"Cnt": 100
},
"Type": 2
}
]
You can see that each element has a Key "Data" and "Type" (Must), but with different 'Type' comes the different 'Data' field.
Could you please suggest a efficiency way to construct this kind of response to Golang structure?
Thanks.
This should work for you
type Test []struct {
Data map[string]interface{} `json:"Data"`
Type int `json:"Type"`
}
since the only variable keys and values are in Data, make that a map instead and look for the keys inside based on the type received
So I have ran into such data format:
{
"i": {
"hid|15#aid|9305#h|Openjobmetis Varese#a|Germani Basket Brescia#h2|VARESE#a2|BRESCIA#round|1019#nat|ita#hcolors": {
"bg|851010#g1|920000#g2|ad0b0b#g3|800000#c|"
},
"acolors": {
"bg|037f43#g1|00582d#g2|0fb966#g3|037f43#c|"
},
"hp|33#vp|20"
},
"idor": 0,
"jr|1#t": 19,
"t2": 30,
"ip|#b": false,
"v": {
"h": 0,
"a": 0,
"t": 30,
"h2": 12,
"a2": 12
}
}
I have never seen such structure and I could not find any sources to explain me this format. Actually I was not even sure how to search it.
So yeah, my question is, what is this data format and how can I handle it?
Looks like JSON.
It appears some data was also encoded as pipe-delimited string values in the JSON.
Ok, right after posting this question, I was able to decode this JSON. It seemed like a JSON all along but these pipes were kind of intimidating. This is how I solved it eventually.
function jsonDecode(json){
if(!json) return null;
json = json.replace(/#/g, '","').replace(/\|/g, '":"').replace(/%/g, '"},{"');
return JSON.parse(json);
}
Great! This question is now answered. Thanks everybody!
I'm trying to convert some API response data into a Ruby hash or array so I can more easily work with it. Here's the JSON string being returned by the API:
[
{
"id": 2,
"name": "TestThing",
"token": "B2CA27221DB976E48248F26756289B91"
},
{
"id": 3,
"name": "AnotherTestThing",
"token": "EF16E5F20B8463E48DBF3BA8F0E1102A"
}
]
I believe that is a JSON array? I tried doing JSON.parse on that string, but got (JSON::ParserError)r/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/json/common.rb:148:in 'parse': 746: unexpected token at '1511
What is the best way to convert this into something I can easily work with? My real goal here is to iterate over the tokens returned.
require 'json'
array = '[
{
"id": 2,
"name": "TestThing",
"token": "B2CA27221DB976E48248F26756289B91"
},
{
"id": 3,
"name": "AnotherTestThing",
"token": "EF16E5F20B8463E48DBF3BA8F0E1102A"
}
]'
JSON.parse(array)
My question did not show the full string I was trying to JSON.parse. I only put what I was trying to parse. I accidentally left some floating data before the JSON part of my string. Now that I have deleted that, it is working.