Malformed JSON in Yahoo response - json

I am trying to get Yahoo user email by decoding ID Token like here in Ruby. I have a token docoding it with Base64.decode64, parsing JSON and here problem come up. String I am trying to parse to JSON is invalid.
Sorry for this copy-paste have problem with formatting it.
START
{"at_hash":"pNgANAsIViDvJ7OCgSk1hw==","sub":"C4SNYQZSHET33BLBTUM3NU2KVP","email_verified":true,"birthdate":"1984","iss":"https://api.login.yahoo.com","profile_images":{"image64":"https://ws.progrss.yahoo.com/progrss/v1/user/C4SNYQZSHET33BLBTUM3NU2KVP/profile/picture
[XYNL΋XZ݌KӖTVU [Y^OM
SLӕLՔ
ٚ[KX\O˚[Y^OLNL
N[XY΋XZ݌KӖTVU
SLӕLՔ
ٚ[KX\Bw6S##"vS3"#&GG3w2&w'726&w'72cW6W"E44UC34$ET$e&f7GW&Pͥȉ艕ULٕ}興Ր艑IYY])DYY9!5)4)9]9!EL4Ռa)]9aE}ѥ͕݅}ذЈ݅兡
END
It looks like the string is cut before its end. Is there any way to get proper JSON?
I am using Ruby 2.4.1

Related

Sending Json looking formatted plain text to be de-serialized

If you send plain Json formatted un-serialized text from a web api and have it be de-serialized in a C# function using the jsonConvert.DeserializeObject functional? I have a co-worker who created a web api in the cloud and he sends plain text formatted to look like un-serialized Json which I try to use C# functionality to Deserialize but when I try to convert what is sent into Model classes it fails. I am telling him that the C# JsonConvert.SerializeObject must be used or it won't work. Can someone help clarify this with me?
Your colleague is right. JSON strings need to be de-serialized to turn them into objects.
Moreover, the things you call "plain text formatted to look like JSON" are JSON strings. JSON is plain text (in UTF8, with syntax rules).
Let's say you have some data structure in your program that you want to send over the network. The network can only send series of bytes, so whatever your structure was, you need to turn it into that -- you need to serialize it. JSON is one way of doing that, e.g.
'{"example": "some data"}'
is a string containing JSON. It is serialized, it's just a string of bytes to send over the network.
On the receiving end, you need to deserialize it back into some data structure, some type of hash map or dictionary or whatever it's called in C# probably.
If what you try "fails", you could ask a much more specific question showing what you tried with what data and how exactly it failed.

How do I convert the following data serialization format into POJO or JSON?

I was expecting a JSON string while testing an API using Postman, but instead got this:
{city=Shanghai, work=112-454-7895, fax=788-899-7899}
Obviously I cannot put that into Google and ask what format is it, hence I am asking it here. Postman also says it is a 'bad string'.
I have never seen the above data serialization format. If someone can point the format out to me I would be able to find and use a converter. Additional suggestion with converting it to POJO or JSON are welcome as well.
I figured out that the above format is a stringified version of a HashMap<String, String>, and that there is no direct way to convert it into JSON/POJO. Converting it into json string requires additional work but is fairly straightforward.

JMeter Groovy convert JSON response to string

I've been looking through various solutions for converting JSON responses to string, but I'm still getting something wrong.
I'm trying to read the response from a post request, convert it to a string and modify it (using groovy), then pass it on the next request. The problem seems to be in the groovy script, it's not reading in the response from the first HTTP request and I'm not sure how to fix that.

json request issue with newline (\n) in ios

I am using afnetworking for json request, and I am passing string like "hello
world". afnetworking json data converts it to "hello\\nworld". but php webservice getting it as "hello\nworld"(my json string). can any one give solution for it. please reply as soon as possible.
Thank you in advance.

json-rpc malformed request with

I'm building an application that communicates with a django backend using json-rpc. So far all has been working well. However I've found an anomaly in sending " ". As far as I know the request works fine, however django interprets the response badly. I've reproduced a simplified request and response below:
Request:
{"jsonrpc":"2.0","id":"1","method":"test","params":
{"id":"80","name":"tests","introduction":"hello there"}}
Django receives:
<QueryDict:u'{"jsonrpc":"2.0","id":"1","method":"test","params":
{"id":"80","name":"tests","introduction":"hello ': [u''], u'nbsp': [u''], u'there"}}': [u'']}>
Expected response:
<QueryDict: {u'{"jsonrpc":"2.0","id":"1","method":"test","params":
{"id":"80","name":"tests","introduction":"hello there"}}': [u'']}>
It seems like django interprets the & and the ; as special characters and so creates an unexpected dictionary in its request.POST variable.
What do I need to do to make sure that the json string doesn't get malformed? I have tried encoding it using the php htmlspecialchars() method, but since that doesn't remove the '&' the problem persists.
Any help will be much appreciated.
Django is handling the (POST?) request by decoding the body (your json string) as if it were a query string, and not a json.
Within a query string, & and ; denote the end of a key:value pair. Splitting up your request body on those two characters yields the key:value pairs you see in the Django QueryDict.
You need to get hold of the POST request body and explicitly decode it to a dict yourself using either the standard lib json, or simplejson module.
I have little experience with Django specifically, but I imagine that somewhere in your view handler you would do something akin to:
try:
data = json.loads(requesst.raw_post_data)
## work with the data...
except ValueError:
## do something...
No doubt Django provides a way to move this json handling out of your views, and to somewhere more suitable.