Making the following request to the Microsoft Academic gives malformed JSON:
https://westus.api.cognitive.microsoft.com/academic/v1.0/interpret?
query=albert einstein&complete=0&count=2&offset=2&model=latest
The result is as follows
Request-Context: appId=cid-v1:7cd06f0e-6d73-46a5-9c10-4ebe681d0156
apim-request-id: 8eec6818-55d3-4b7c-b1c3-b4c6236f0173
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
Date: Tue, 31 Oct 2017 01:02:11 GMT
X-Powered-By: ASP.NET
Content-Length: 681
Content-Type: application/json
{
"query": "albert einstein",
"interpretations": [,
{
"logprob": -69.749,
"parse": "<rule name=\"#GetPapers\"><attr name=\"academic#W\">albert</attr> <attr name=\"academic#F.FN\">einstein</attr></rule>",
"rules": [{
"name": "#GetPapers",
"output": {
"type": "query",
"value": "And(W='albert',Composite(F.FN=='einstein'))"
}
}]
},
{
"logprob": -118.575,
"parse": "<rule name=\"#GetPapers\"><attr name=\"academic#W\">albert</attr> <attr name=\"academic#W\">einstein</attr></rule>",
"rules": [{
"name": "#GetPapers",
"output": {
"type": "query",
"value": "And(W='albert',W='einstein')"
}
}]
}
]
}
Notice the leading comma on the third line of the JSON, at the beginning of the interpretations array. I suspect there's a bug in the code used to paginate results. I'm working in Python, and that leading comma breaks every parser I can think of including a straight eval. I think I can handle it with a String.replace before using json.loads, but that's an ugly solution. Are there better alternatives? And am I correct to think this is a bug?
Related
I've trying to learn JSON along with using web hooks. I'm trying to use postman to test my code but I'm getting an error. Anyone have any ideas?
POST /api/webhooks/XXXXXXXXXXXXXXX HTTP/1.1
Host: discord.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: dbb93a2b-fced-8bd6-df89-XXXXXXXXXXX
{
"embeds":
[{
"ticker": "{{ticker}}",
"exchange": "{{exchange}}",
"interval": "{{interval}}",
"date": "{{date}}",
"timenow": "{{timenow}}"
}]
}
error message
{
"embeds": [
"0"
]
}
Discord docs for JSON
https://discord.com/developers/docs/resources/channel#create-message
Good afternoon,
I am currently struggling a bit with index creation requests towards a hosted Elastic Search Service (FacetFlow), more precisely, the ES server returns a JsonParseException and returns a http 500 response and the Nest client (correctly) reports the index creation request to have failed (non valid/not acknowledged etc)
I sniffed the http traffic via fiddler and what gets sent over is the following:
POST https://myhostedesinstance.west-eu.azr.facetflow.io/users-dev HTTP/1.1
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip,deflate
Authorization: Basic <cutforobviousreasons>
Host: myhostedesinstance.west-eu.azr.facetflow.io
Content-Length: 891
{
"settings": {
"index": {
"number_of_replicas": 0,
"number_of_shards": 1
}
},
"mappings": {
"user": {
"_all": {
"enabled": false
},
"_ttl": {
"enabled": false
},
"properties": {
"dateOfBirth": {
"index": "not_analyzed",
"type": "date"
},
"gender": {
"index": "not_analyzed",
"type": "integer"
},
"username": {
"index": "not_analyzed",
"type": "string"
},
"usernameSuggestions": {
"type": "completion",
"payloads": false
},
"id": {
"index": "not_analyzed",
"type": "string"
},
"createdAtUtc": {
"index": "not_analyzed",
"type": "date"
}
}
}
}
}
..and what I get back is the following:
HTTP/1.1 500 Server Error
Server: nginx/1.4.7
Date: Wed, 01 Jul 2015 21:17:11 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 199
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
{"error":"JsonParseException[Illegal character ((CTRL-CHAR, code 31)): only regular white space (\\r, \\n, \\t) is allowed between tokens\n at [Source: [B#a4fb74c; line: 1, column: 2]]","status":500}
I am using Nest 1.6.1 and Json.Net 7.0.1 and to 'me' that Json sent over to the server looks fine.. or am I missing something? Does anyone happen to know what might be going on?
I have not changed any serialization settings of Nest/Json.Net so I am somewhat confused why this might happen.
I have a webapi method that I want to switch oData paging etc on.
I followed the example in http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options
My method looks like:
public PageResult<UserViewModel> GetUsers(ODataQueryOptions<UserViewModel> options)
{
var settings = new ODataQuerySettings()
{
PageSize = 2
};
var results = UserLogic.GetUsers(userId, UserManager, _db);
var filtered = options.ApplyTo(results, settings);
var pagedResult = new PageResult<UserViewModel>(
filtered as IEnumerable<UserViewModel>,
Request.GetNextPageLink(),
Request.GetInlineCount());
return pagedResult;
}
That the count is populated and the next page link is there and the correct oData options are applied i.e. sort order etc. When I return it in my api method, the correct data comes back, but the count and next link don't appear in my json.
Am I missing a setting to turn this on?
i.e. this is my json response:
HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-RequestID: b215962b-6a4a-431d-9850-7ecbf808538e
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcUmVwb3NpdG9yaWVzXEdpdEh1YlxxbGRyYS1wb3J0YWxccWxkcmEtcG9ydGFsLldlYlxxbGRyYS5iYXNlbGluZS5hcGlcYXBpXHVzZXJz?=
X-Powered-By: ASP.NET
Date: Fri, 04 Apr 2014 05:16:53 GMT
Content-Length: 554
[
{
"Id": "500e6f96-b2bd-48d9-8181-5bbc39c673f6",
"UserName": "adam#test.com",
"Organisation": {
"Id": "f179bc35-89b8-e311-9dfd-0050569b4cee",
"Name": "Black and White Cabs Pty Ltd",
"IsActive": true,
"LastUpdatedDate": "2014-04-03T11:35:26.167"
},
"IsLockedOut": false,
"Roles": []
},
{
"Id": "0d661d1b-9e52-4f2f-baec-3eb89197bb6d",
"UserName": "bob#test.com",
"Organisation": null,
"IsLockedOut": false,
"Roles": [
"Service Administrator"
]
}
]
This should work.
Be sure to remove the [EnableQuery] attribute if it is being applied to your method or controller. This will cause the returned JSON to not include the count and next link.
I've made composite templates and had them working before, but I'm suddenly getting an error and have no idea why this is causing an issue. Here's my request:
POST https://demo.docusign.net/restapi/v2/accounts/356019/envelopes HTTP/1.1
Host: demo.docusign.net
X-DocuSign-Authentication: <DocuSignCredentials><Username>test#gmail.com</Username><Password>*****</Password><IntegratorKey>****</IntegratorKey></DocuSignCredentials>
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Content-Length: 807319
Expect: 100-continue
Connection: Keep-Alive
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"emailSubject": "Please Docusign this",
"emailBlurb": "This is a test... Also sign this form",
"enableWetSign": "true",
"status": "sent",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "test#gmail.com",
"name": "test",
"recipientId": "1"
}
]
}
}],
"document":
{
"documentId": "1",
"name": "test0",
"fileExtension": "pdf"
}
}
]
}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="test0.pdf"; documentid="1"
<pdf bytes here>
--MY_BOUNDARY--
I have this working with server templates, but it seems like anything that requires the document object gives me a bad request. The request I'm getting is:
Request Error: BadRequestDocuSign Error: {
"errorCode": "UNSPECIFIED_ERROR",
"message": "the document is corrupt, rebuilding failed"
}
I've read the pdf bytes in another program and have successfully created a pdf from it, so I'm not sure what could be causing this issue. Does anybody know what the problem may be? Thank you for your time.
I'm playing around with Google Mirror API and creating out some sample apps. Since I'm not an explorer I'm using Sturm's Mirror API.
I'd like to know the valid JSON format to share a piece of text to a particular Google Glass contact. I tried the following JSON in API explorer but got a 400 bad request error. Also is there a way to do the same through Google Glass Playground rather than API explorer?
{
'recipients': [
{
'acceptTypes': [
'text/plain'
],
'displayName': 'myglassapp',
'imageUrls': [
'https://myglassapp.appspot.com/images/welcome.jpg'
],
'id': 'babu_glass_app'
}
],
'kind': 'mirror#timelineItem',
'isDeleted': False,
'text' : 'Hello World',
}
Error:
400 Bad Request
- Hide headers -
cache-control: private, max-age=0
content-encoding: gzip
content-length: 118
content-type: application/json; charset=UTF-8
date: Thu, 30 May 2013 08:05:47 GMT
expires: Thu, 30 May 2013 08:05:47 GMT
server: GSE
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
Oops.. My bad. Python dict to JSON problem. False instead of false. And now the card is getting inserted.
{
'recipients': [
{
'acceptTypes': [
'text/plain'
],
'displayName': 'myglassapp',
'imageUrls': [
'https://myglassapp.appspot.com/images/welcome.jpg'
],
'id': 'babu_glass_app'
}
],
'kind': 'mirror#timelineItem',
'isDeleted': false,
'text' : 'Hello World',
}