Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm getting following string when requested for json object.
{
"singular": "Financial Report",
"plural": "Financial Reports",
"statusId": "A",
"records": [
{
"id": 131114,
"companyId": 645588,
"userId": 5520,
"title": "Annual Report",
"typeId": "AR",
"statusId": "A",
"periodDate": new Date(1409457600000),
"isImmediate": true,
"createdDate": new Date(1419276796000),
"lastModifiedDate": new Date(1419276796000),
"releaseDate": new Date(1419276796000),
"releaseDateTimeFormatted": "Dec 22, 2014 02:33 PM",
"releaseDateFormatted": "Dec 22, 2014",
"canDistribute": true,
"wasDistributed": false,
"companyName": "Sunridge Gold Corp.",
"typeName": "Annual Report",
"name": "Annual Report - Annual Report",
"statusDescript": "Active",
"userName": "Doris Meyer",
"symbol": "SGCNF",
"primarySymbol": "SGCNF",
"primaryExchange": "OTC Link",
"isCaveatEmptor": false,
"edgarSECFiling": false
}
],
"sortOn": "releaseDate",
"sortDir": "DESC",
"totalRecords": 76165,
"pages": 3047,
"currentPage": 4,
"pageSize": 25
}
I was trying to parse it using google gson library it throwing com.google.gson.stream.MalformedJsonException
Is there any way to avoid new Date in json string above.
That is not JSON. Rather it is Javascript which includes calls to a Javascript (I think) method called newDate.
Is there any way to avoid new Date in json string above.
It depends on what is generating the not-JSON string! If you can fix that, you are good to go. Otherwise, I don't imagine that any JSON parser is going to cope with it.
For the record, the syntax for JSON is defined on the http://json.org site. If someone argues that the stuff you have shown us is real JSON, point them at the syntax ... and at the ECMA standard that that page cites as the authoritative source.
Related
so i have my project there is this part where there are 2 one to many relation ship to the same entity
what happens is that the response on the get request on postman come like this :
the one to many relationship is writen the same for both elements
{
"elemnt1withonetomany": {
"id": 2,
"name": "something",
"last_name": "something",
"email": "something"
},
"elemnt2withonetomany": {
"#id": 4,
"id": 4,
"code": "details",
"email": "details",
"name": "details",
"lastname": "details"
},
{
"elemnt1withonetomany": {
"id": 2,
"name": "something",
"last_name": "something",
"email": "something"
},
"element2withonetomany": 4,
}
so is there any way to make the get request gives the same form of information with elemnt2withonetomany
i kinda found where it came from but then it's gonna need a lot of JsonBackReference and similar annotations
and yep it was from the #JsonIdentityInfo on top of the entities
kinda took me a while to find the source so i'm just gonna post what i found if someone needed it
so my new question is there a way to by pass it without deleting this one
I need to process a big JSON payload(~1MB) coming from an API, a portion of the JSON is something like this:
{
"id": "013dd2a7-fec4-4cc5-b819-f3cf16a1f820",
//more attributes
"entry_mode": "LDE",
"periods": [
{
"type": "quarter",
"id": "fe96dc03-660c-423c-84cc-e6ae535edd2d",
"number": 1,
"sequence": 1,
"scoring": {
//more attribtues
},
"events": [
{
"id": "e4426708-fadc-4cae-9adc-b7f170f5d607",
"clock": "12:00",
"updated": "2013-12-22T03:41:40+00:00",
"description": "J.J. Hickson vs. DeAndre Jordan (Blake Griffin gains possession)",
"event_type": "opentip",
"attribution": {
"name": "Clippers",
"market": "Los Angeles",
"id": "583ecdfb-fb46-11e1-82cb-f4ce4684ea4c",
"team_basket": "left"
},
"location": {
"coord_x": 572,
"coord_y": 296
},
"possession": {
"name": "Clippers",
"market": "Los Angeles",
"id": "583ecdfb-fb46-11e1-82cb-f4ce4684ea4c"
}
},
//more events
]
}
]
}
This is a nearly-realtime API that I need to process only the events, identify a set of event UUIDs, look for duplicates in the database and save new events.
I could use a JSONObject/JSONArray or use regex with string parsing to and fetch the events portion. Processing time is critical since this should be nearly-realtime and memory efficiency is important since there can be multiple payloads coming in at once.
Which one is more efficient for this use case?
Use a proper streaming JSON parser. You know what you want to pull out of the stream, you know when you can quit parsing it, so read the stream in small, manageable chunks, and quit as soon as you know you are done.
Circa 2017, I'm not aware of any browser/native JSON streaming APIs, so you'll need to find a Javascript-based streaming library. Fortunately, streaming is not a new concept, so there are a number of options already in existence:
http://oboejs.com/
https://github.com/dominictarr/JSONStream
https://github.com/creationix/jsonparse
https://github.com/dscape/clarinet
http://danieltao.com/lazy.js/demos/json/
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm using RestAssured to test an API.
I have the following, wow can I test the post method?
{
"name": "Test",
"email": "test#email.com",
"occupation": [{
"id": 1,
"feature": {
"id": 2
},
"company": 7777,
}]
}
"Occupation" is another table, how can I on both tables?
I have tried this:
.body("{\"name\": \"test\", \"email\": \"test#email.com\", \"occupation\": {\"id\": 15, \"feature\": {\"id\": 15}", \"company\": \"7777\"}}")
But the error
"Can not deserialize instance of java.util.ArrayList out of
START_OBJECT token"
is shown.
{\"id\": 15, \"feature\": {\"id\": 15}", \"company\": \"7777\"}}"
Try using JSON array here, too!
f.e.:
[{\"id\": 1, \"feature\": {\"id\": 2}", \"company\": \"7777\"}]"
My question is how can I know which JSON schema to use to validate a particular JSON document? I specified the URL to the schema in the id field from it. Is this enough? Should I put the id in the JSON? I am not sure I understand how to connect a JSON to a specific JSON Schema.
Here is my schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "url/schema.json",
"title": "title",
"definitions": {
"emailObject": {
"type": "object",
"properties":{
"name": {
"description": "The name of the customer",
"type": "string",
"maxLength": 200
},
"email": {
"description": "The email of the customer",
"type": "string",
"format": "email",
"maxLength": 100
}
}
}
}
To add to and clarify Tom's answer, here is an example of how you can link a JSON document to a JSON Schema. There is no standard way of doing this outside the context of an HTTP response. If that is something you need, you will have to come up with your own strategy.
GET /data/my-data HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
Link: </schema/my-schema> rel=describedby
{ "name": "Fake Fakerson", "email": "fake#fakerson.com" }
GET /schema/my-schema HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/schema+json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "url/schema.json",
"title": "title",
"definitions": {
"emailObject": {
"type": "object",
"properties":{
"name": {
"description": "The name of the customer",
"type": "string",
"maxLength": 200
},
"email": {
"description": "The email of the customer",
"type": "string",
"format": "email",
"maxLength": 100
}
}
}
}
}
According to 10.1 of the specification:
It is RECOMMENDED that instances described by a schema/profile provide
a link to a downloadable JSON Schema using the link relation
"describedby", as defined by Linked Data Protocol 1.0, section 8.1
[W3C.REC-ldp-20150226]. (emphasis mine)
This would appear to describe exactly the behaviour you require, however, a casual perusal of the Linked Data Protocol section 8.1 leaves us none the wiser:
The relationship A describedby B asserts that resource B provides a
description of resource A. There are no constraints on the format or
representation of either A or B, neither are there any further
constraints on either resource (emphasis mine)
After a quick google search, I found this question, which at first glance would appear to be duplicated by your question. However, upon deeper inspection, the question is actually about inheritance within schemas, not the referencing of a schema from it's supported instances.
One of the answers, rather intriguingly, provides a solution which draws on the JSON-Hyper-schema standard - an attempt to extend the JSON-schema standard to support the definition of application-level semantics.
The way it achieves this is by use of the links collection:
{
...
"links":[
{
"rel":"describedby",
"href":"{+fileType}"
}
]
}
It turns out that this is based on another standard RFC5988 - Web Linking which happens to be the same standard which allows us to load CSS into HTML pages.
As #Jason points out in his comment -
Your first quote, the one from the spec, is the right way to do it.
The linked data definition of describedby does not contradict the JSON
Schema spec. It's a purposefully broad definition so it can be applied
to any media type that describes data. That includes JSON Schema, XML
Schema, or anything else.
So, it would appear that including a links collection in your schema instance would be the correct way to reference the schema. So in your specific case, you could do this:
{
...
"links":[
{
"rel":"describedby",
"href":"url/schema.json" // I assume!!
}
]
}
Even though this may be correct, I don't know how many JSON parsers will respect this when resolving to an actual schema via the link.
Hi guys I encountered a problem on handling json on Android today. The json I got from the web service looks like the below:
e.g. from https://serviice.somewebite.com/list.json, I got this :
{
"task_id": 5,
"profile_id": 3,
"text": "{profileName} wrote {taskName}",
"created_at": "2015-08-10",
"event": "post"
},
{
"task_id": 6,
"profile_id": 2,
"text": "{profileName} wrote {taskName}",
"created_at": "2015-10-24",
"event": "post"
},
...... (and many similar entities)
the task_id is actually an id linking to other remote json, for the first entity, task_id = 5, which I should get the task json from https://serviice.somewebite.com/task/5.json, like the below:
{
"id": 5,
"name": "Clean house",
"description": "Clean every room in the house",
"state": "assigned",
}
And it is the similar way to get the profile json in the list.json file.
I have been handling json with pojo + retrofit + GSON before, but all the content are in one json, not like this.
What I want is getting all the needed jsons and show them in a listview including created_at(in list.json), task_description(in task.json), task_name(in task.json)
Currently I can only figure out one way to hanlde it. First get the list.json , and then scan the task ids and profile ids in list.json, and then get all the needed json via multiple asynchronous http requests. Seems too much boiler plate code here.
Is there an existing library/framework for this scenario? I am on Android platform using Java. Thanks a lot!