I'm trying to create POJOs for the following JSON from the API at https://developers.google.com/qpx-express/v1/trips/search
When I copy & paste this into http://www.jsonschema2pojo.org/ I get an error at line 5 "requestId": string, saying "There's a problem: Unrecognized token 'string': was expecting ('true', 'false' or 'null') (line 5, column 24)"
If I change string to an actual example string it works fine. Can this json to pojo converter not handle JSON in this format? It just seems a bit tedious to have to change all the data types to samples instead.
{
"kind": "qpxExpress#tripsSearch",
"trips": {
"kind": "qpxexpress#tripOptions",
"requestId": string,
"data": {
"kind": "qpxexpress#data",
"airport": [
{
"kind": "qpxexpress#airportData",
"code": string,
"city": string,
"name": string
}
],
"city": [
{
"kind": "qpxexpress#cityData",
"code": string,
"country": string,
"name": string
}
],
"aircraft": [
{
"kind": "qpxexpress#aircraftData",
"code": string,
"name": string
}
],
"tax": [
{
"kind": "qpxexpress#taxData",
"id": string,
"name": string
}
],
"carrier": [
{
"kind": "qpxexpress#carrierData",
"code": string,
"name": string
}
]
},
"tripOption": [
{
"kind": "qpxexpress#tripOption",
"saleTotal": string,
"id": string,
"slice": [
{
"kind": "qpxexpress#sliceInfo",
"duration": integer,
"segment": [
{
"kind": "qpxexpress#segmentInfo",
"duration": integer,
"flight": {
"carrier": string,
"number": string
},
"id": string,
"cabin": string,
"bookingCode": string,
"bookingCodeCount": integer,
"marriedSegmentGroup": string,
"subjectToGovernmentApproval": boolean,
"leg": [
{
"kind": "qpxexpress#legInfo",
"id": string,
"aircraft": string,
"arrivalTime": string,
"departureTime": string,
"origin": string,
"destination": string,
"originTerminal": string,
"destinationTerminal": string,
"duration": integer,
"operatingDisclosure": string,
"onTimePerformance": integer,
"mileage": integer,
"meal": string,
"secure": boolean,
"connectionDuration": integer,
"changePlane": boolean
}
],
"connectionDuration": integer
}
]
}
],
"pricing": [
{
"kind": "qpxexpress#pricingInfo",
"fare": [
{
"kind": "qpxexpress#fareInfo",
"id": string,
"carrier": string,
"origin": string,
"destination": string,
"basisCode": string,
"private": boolean
}
],
"segmentPricing": [
{
"kind": "qpxexpress#segmentPricing",
"fareId": string,
"segmentId": string,
"freeBaggageOption": [
{
"kind": "qpxexpress#freeBaggageAllowance",
"bagDescriptor": [
{
"kind": "qpxexpress#bagDescriptor",
"commercialName": string,
"count": integer,
"description": [
string
],
"subcode": string
}
],
"kilos": integer,
"kilosPerPiece": integer,
"pieces": integer,
"pounds": integer
}
]
}
],
"baseFareTotal": string,
"saleFareTotal": string,
"saleTaxTotal": string,
"saleTotal": string,
"passengers": {
"kind": "qpxexpress#passengerCounts",
"adultCount": integer,
"childCount": integer,
"infantInLapCount": integer,
"infantInSeatCount": integer,
"seniorCount": integer
},
"tax": [
{
"kind": "qpxexpress#taxInfo",
"id": string,
"chargeType": string,
"code": string,
"country": string,
"salePrice": string
}
],
"fareCalculation": string,
"latestTicketingTime": string,
"ptc": string,
"refundable": boolean
}
]
}
]
}
}
Valid json requires string values to be in quotes. So quoting the key but not the value like-> "id" : string, does not make much sense. Read carefully "In the request body, supply data with the following structure" You are not supplying any data
Well, the example JSON code on the page uses data types in quotes, so "string" instead of string. You could do just that:
(warning! the following example is nonsense if you want other types than strings!)
{
"kind": "qpxExpress#tripsSearch",
"trips": {
"kind": "qpxexpress#tripOptions",
"requestId": "string",
"data": {
"kind": "qpxexpress#data",
"airport": [
{
"kind": "qpxexpress#airportData",
"code": "string",
"city": "string",
"name": "string"
}
],
"city": [
{
"kind": "qpxexpress#cityData",
"code": "string",
"country": "string",
"name": "string"
}
],
"aircraft": [
{
"kind": "qpxexpress#aircraftData",
"code": "string",
"name": "string"
}
],
"tax": [
{
"kind": "qpxexpress#taxData",
"id": "string",
"name": "string"
}
],
"carrier": [
{
"kind": "qpxexpress#carrierData",
"code": "string",
"name": "string"
}
]
},
"tripOption": [
{
"kind": "qpxexpress#tripOption",
"saleTotal": "string",
"id": "string",
"slice": [
{
"kind": "qpxexpress#sliceInfo",
"duration": "integer",
"segment": [
{
"kind": "qpxexpress#segmentInfo",
"duration": "integer",
"flight": {
"carrier": "string",
"number": "string"
},
"id": "string",
"cabin": "string",
"bookingCode": "string",
"bookingCodeCount": "integer",
"marriedSegmentGroup": "string",
"subjectToGovernmentApproval": "boolean",
"leg": [
{
"kind": "qpxexpress#legInfo",
"id": "string",
"aircraft": "string",
"arrivalTime": "string",
"departureTime": "string",
"origin": "string",
"destination": "string",
"originTerminal": "string",
"destinationTerminal": "string",
"duration": "integer",
"operatingDisclosure": "string",
"onTimePerformance": "integer",
"mileage": "integer",
"meal": "string",
"secure": "boolean",
"connectionDuration": "integer",
"changePlane": "boolean"
}
],
"connectionDuration": "integer"
}
]
}
],
"pricing": [
{
"kind": "qpxexpress#pricingInfo",
"fare": [
{
"kind": "qpxexpress#fareInfo",
"id": "string",
"carrier": "string",
"origin": "string",
"destination": "string",
"basisCode": "string",
"private": "boolean"
}
],
"segmentPricing": [
{
"kind": "qpxexpress#segmentPricing",
"fareId": "string",
"segmentId": "string",
"freeBaggageOption": [
{
"kind": "qpxexpress#freeBaggageAllowance",
"bagDescriptor": [
{
"kind": "qpxexpress#bagDescriptor",
"commercialName": "string",
"count": "integer",
"description": [
"string"
],
"subcode": "string"
}
],
"kilos": "integer",
"kilosPerPiece": "integer",
"pieces": "integer",
"pounds": "integer"
}
]
}
],
"baseFareTotal": "string",
"saleFareTotal": "string",
"saleTaxTotal": "string",
"saleTotal": "string",
"passengers": {
"kind": "qpxexpress#passengerCounts",
"adultCount": "integer",
"childCount": "integer",
"infantInLapCount": "integer",
"infantInSeatCount": "integer",
"seniorCount": "integer"
},
"tax": [
{
"kind": "qpxexpress#taxInfo",
"id": "string",
"chargeType": "string",
"code": "string",
"country": "string",
"salePrice": "string"
}
],
"fareCalculation": "string",
"latestTicketingTime": "string",
"ptc": "string",
"refundable": "boolean"
}
]
}
]
}
}
Related
I have Json schema as input I want to know whether there is a method by which I can generate sample json output. Do we have any such library in java which I can use?
{
"title": "InputSchema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
}
},
"required": ["firstName", "lastName"]
}
output =>
{
"firstName" : "FirstName",
"lastName" : "LastName"
}
How to get a new list from the list of objects?
I need a new list of objects to POST request
this list of objects i get from response:
{
"success": true,
"body": {
"users": [
{
"type": "unknown",
"data": [
{
"id": "8",
"firstName": "Jackson",
"lastName": "Baker",
"group": "false"
},
{
"id": "11",
"firstName": "Charlotte",
"lastName": "Garcia",
"group": "false"
},
{
"id": "7",
"firstName": "Henry",
"lastName": "Thompson",
"group": "false"
},
{
"id": "24",
"firstName": "Elijah",
"lastName": "Miller",
"group": "false"
}
]
}
]
}
}
I need to form a new object from response:
{
"success": true,
"body": {
"users": [
{
"type": "unknown",
"data": [
{
"id": "8",
"group": "false"
},
{
"id": "11",
"group": "false"
},
{
"id": "7",
"group": "false"
},
{
"id": "24",
"group": "false"
}
]
}
]
}
}
This new list of object I need to post a request.
I have a JSON Schema, but i don't know how i can make this structure.
My problem is that I can't get the values from fields. I'm using the path "body.users.data.find {it.id} .id" but it finds the id array but I need a users list with values from two fields.
As the users node and data node are all list type, you need use two loop:
import groovy.json.JsonSlurper
// text is your json response text
def result = new JsonSlurper().parseText(text)
result.body.users.each{it.data.each{it.remove("firstName");it.remove("lastName")}}
// result is the what you wanted
println(result)
My Format
{
"iList": [
{
"ADDRESS1": "string",
"CITY": "string",
"COUNTRY": "string",
"EMAIL_ADDRESS": "string",
"FIRST_NAME": "string",
"LAST_NAME": "string",
"PRIMARY_PHONE_NUMBER": "string",
"STATE_PROVINCE": "string",
"ZIP_CODE": "string"
}
],
"iaList": [
{
"ATTRIBUTE_NAME": "string",
"CUSTOM_PERMISSION": "string",
"Id": "string",
"GLOBAL_PERMISSION": "string"
},
{
"ATTRIBUTE_NAME": "string",
"CUSTOM_PERMISSION": "string",
"Id": "string",
"GLOBAL_PERMISSION": "string"
},
{
"ATTRIBUTE_NAME": "string",
"CUSTOM_PERMISSION": "string",
"Id": "string",
"GLOBAL_PERMISSION": "string"
}
],
"Uplift": [
{
"AGE": 0,
"AUTOMOBILE": "string",
"CHILD_AGES": "string",
"DATE_OF_BIRTH": "string",
"EDUCATION": "string",
"GENDER": "string",
}
]
}
I have created a main model class with List and each individual model class. But i have no idea of doing iaList. How can i pass multiple json object inside json array . Please anyone help me
I have following JSON
"ID": "234AS",
"Name": "SynchronousMate",
"Type": "Node",
"SubType": "SubNode",
"Dynamic": "Yes",
"DisplayName": "Sync",
"Direct": "Yes",
"Category": "IT",
"Properties": {
"Property": [
{
"Name": "A",
"Value": "Anant"
},
{
"Name": "B",
"Value": "Bharat"
},
{
"Name": "C",
"Value": "Cynus"
},
{
"Name": "D",
"Value": "Dynana"
},
{
"Name": "E",
"Value": "Elegant"
},
{
"Name": "Bank",
"Value": "BOB"
},
{
"Name": "ipAddress",
"Value": "101.90.34.12"
},
{
"Name": "siteName",
"Value": "BRS-WDM-PSS-X7A6"
},
{
"Name": "Longitude",
"Value": 0
},
{
"Name": "FullName",
"Value": "network:10.254.0.46"
},
{
"Name": "NumberOfShelves",
"Value": 0
},
{
"Name": "GEOCODE.Latitude",
"Value": 0
}
]
},
"Properties": ""
}
..............................
..............................
How to convert this JSON to like this
{
"ID": "234AS",
"Name": "SynchronousMate",
"Type": "Node",
"SubType": "SubNode",
"Dynamic": "Yes",
"DisplayName": "Sync",
"Direct": "Yes",
"Category": "IT",
"A" : "Anant",
"B" : "Bharat",
"C" : "Cynus",
"D" : "Dynana",
"E" : "Elegant",
"Bank" : "BOB",
"ipAddress" : "101.90.34.12",
"siteName" : "BRS-WDM-PSS-X7A6",
"Longitude" : ""0",
"FullName" : "network:10.254.0.46",
"NumberOfShelves" : 0,
"GEOCODE.Latitude" : 0
},
............................
............................
You can loop over properties and create a Map with key the value of Name and as value the value of Value.
In simple terms, Get/Store the Property JsonArray. Then iterate it putting the
elements of array in Map. And then add the map to the other half of JSON.
I got json[] from UI. I have to convert it into Json object how can I convert it with gson. An object which is received is like that:
[{"name":"name","value":"value"},{"name":"first","value":"100"},{"name":"hor","value":"95"},{"name":"conf","value":"95"}],[{"name":"vaRType","value":"INCRE"},{"name":"per","value":"100"},{"name":"hor","value":"95"},{"name":"conf","value":"95"}]
I used JsonObject obj = new JsoParser().parse(jsonStrnig).getAsJsonObject();
but it throws an exception.
Because it is not valid json object.
Your JSON should be the following as currently it's invalid...
[
[
{
"name": "name",
"value": "value"
},
{
"name": "first",
"value": "100"
},
{
"name": "hor",
"value": "95"
},
{
"name": "conf",
"value": "95"
}
],
[
{
"name": "vaRType",
"value": "INCRE"
},
{
"name": "per",
"value": "100"
},
{
"name": "hor",
"value": "95"
},
{
"name": "conf",
"value": "95"
}
]
]