I need to output the JSON result in HTML so that I can use it in Coldfusion. I am getting the data but I do not know how to parse the returned data so that I can use it. I am a newby so be easy on me. I don't know JSON at all and this is the first time I am trying to work work this.
<cfset qpxFields = {
"request": {
"passengers": {
"adultCount": "1"
},
"slice": [
{
"origin": "JNB",
"destination": "MRU",
"date": "2016-12-19"
}
],
"solutions": "1"
}
}/>
<cfhttp url="https://www.googleapis.com/qpxExpress/v1/trips/search?key=AIzaSyB0NN9WYmrkc2Ikq9TVGzzAD_gGoSBSbP4" method="post" result="httpResp" timeout="60">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(qpxFields)#">
</cfhttp>
<cfset getResult = deserializeJSON(httpResp.filecontent)>
<cfoutput>#httpResp.filecontent#</cfoutput>
The result I am getting when outputting the filecontent is the following:
{ "kind": "qpxExpress#tripsSearch", "trips": { "kind": "qpxexpress#tripOptions", "requestId": "ylROS8N2kR4vI8ktC0PQVj", "data": { "kind": "qpxexpress#data", "airport": [ { "kind": "qpxexpress#airportData", "code": "JNB", "city": "JNB", "name": "Johannesburg O.R. Tambo International" }, { "kind": "qpxexpress#airportData", "code": "MRU", "city": "MRU", "name": "Mauritius Sir S. Ramgoolam International" } ], "city": [ { "kind": "qpxexpress#cityData", "code": "JNB", "name": "Johannesburg" }, { "kind": "qpxexpress#cityData", "code": "MRU", "name": "Mauritius" } ], "aircraft": [ { "kind": "qpxexpress#aircraftData", "code": "343", "name": "Airbus A340" } ], "tax": [ { "kind": "qpxexpress#taxData", "id": "EV_001", "name": "South Africa Passenger Safety Charge" }, { "kind": "qpxexpress#taxData", "id": "YQ_F", "name": "MK YQ surcharge" }, { "kind": "qpxexpress#taxData", "id": "YR_I", "name": "MK YR surcharge" }, { "kind": "qpxexpress#taxData", "id": "ZA_001", "name": "South Africa Passenger Service Charge" }, { "kind": "qpxexpress#taxData", "id": "UM_001", "name": "South Africa Asc Charge" }, { "kind": "qpxexpress#taxData", "id": "WC_001", "name": "South Africa Air Passenger Tax" } ], "carrier": [ { "kind": "qpxexpress#carrierData", "code": "MK", "name": "AIR MAURITIUS LTD" } ] }, "tripOption": [ { "kind": "qpxexpress#tripOption", "saleTotal": "ZAR5398.23", "id": "bGXAC5TFGRFO06xEFBzMaA001", "slice": [ { "kind": "qpxexpress#sliceInfo", "duration": 240, "segment": [ { "kind": "qpxexpress#segmentInfo", "duration": 240, "flight": { "carrier": "MK", "number": "852" }, "id": "GB3DFc4zHshnkF7H", "cabin": "COACH", "bookingCode": "T", "bookingCodeCount": 9, "marriedSegmentGroup": "0", "leg": [ { "kind": "qpxexpress#legInfo", "id": "LwsDBsjHUFZrYe5Y", "aircraft": "343", "arrivalTime": "2016-12-19T19:35+04:00", "departureTime": "2016-12-19T13:35+02:00", "origin": "JNB", "destination": "MRU", "originTerminal": "B", "duration": 240, "mileage": 1904, "meal": "Meal" } ] } ] } ], "pricing": [ { "kind": "qpxexpress#pricingInfo", "fare": [ { "kind": "qpxexpress#fareInfo", "id": "AdGb1tIdX7T9uIyT9qTU9OFHTXhaVL0C0ojKd7a7use6", "carrier": "MK", "origin": "JNB", "destination": "MRU", "basisCode": "TAANOWMU" } ], "segmentPricing": [ { "kind": "qpxexpress#segmentPricing", "fareId": "AdGb1tIdX7T9uIyT9qTU9OFHTXhaVL0C0ojKd7a7use6", "segmentId": "GB3DFc4zHshnkF7H" } ], "baseFareTotal": "ZAR3690.00", "saleFareTotal": "ZAR3690.00", "saleTaxTotal": "ZAR1708.23", "saleTotal": "ZAR5398.23", "passengers": { "kind": "qpxexpress#passengerCounts", "adultCount": 1 }, "tax": [ { "kind": "qpxexpress#taxInfo", "id": "ZA_001", "chargeType": "GOVERNMENT", "code": "ZA", "country": "ZA", "salePrice": "ZAR346.00" }, { "kind": "qpxexpress#taxInfo", "id": "EV_001", "chargeType": "GOVERNMENT", "code": "EV", "country": "ZA", "salePrice": "ZAR20.23" }, { "kind": "qpxexpress#taxInfo", "id": "UM_001", "chargeType": "GOVERNMENT", "code": "UM", "country": "ZA", "salePrice": "ZAR24.00" }, { "kind": "qpxexpress#taxInfo", "id": "WC_001", "chargeType": "GOVERNMENT", "code": "WC", "country": "ZA", "salePrice": "ZAR190.00" }, { "kind": "qpxexpress#taxInfo", "id": "YQ_F", "chargeType": "CARRIER_SURCHARGE", "code": "YQ", "salePrice": "ZAR1090.00" }, { "kind": "qpxexpress#taxInfo", "id": "YR_I", "chargeType": "CARRIER_SURCHARGE", "code": "YR", "salePrice": "ZAR38.00" } ], "fareCalculation": "JNB MK MRU 260.69TAANOWMU NUC 260.69 END ROE 14.15458 FARE ZAR 3690.00 XT 20.23EV 24.00UM 190.00WC 346.00ZA 1090.00YQ 38.00YR", "latestTicketingTime": "2016-12-19T06:34-05:00", "ptc": "ADT", "refundable": true } ] } ] } }
I am using CF 10.
Instead of trying to deal with the HTTP response (httpResp.filecontent) look at your deserialized content (getResult). You cannot simply output that variable as ColdFusion creates a structure from the JSON data.
Dump out your deserialzed JSON like this:
<cfdump var="#getResult#">
Looking at that output you will see how ColdFusion has already parsed all of the information for you. You are going to have some structure values and some array values. You will need to use appropriate methods (looping over an array for example) to extract each individual piece of data.
Reply to your comment
Looping in ColdFusion is well documented. To get you started you can look at the Adobe documentation itself - cfloop. The documentation on that page shows how to link over arrays, structures, etc.
Another good reference is Learn CF In a Week - looping.
Looping works when you have to traverse one-dimensional or two-dimensional structs or arrays. When the data combines structs and arrays in 3 or more dimensions, as in this particular problem, then looping is often insufficient as a solution. The complexity will certainly overwhelm most beginners.
A good solution is to play dumb. Start with the result, the structure getResult. Do a dump, as suggested by others earlier. Then simply run through it by eye and drill down to the values.
The list of values is:
getResult.kind
getResult.trips.data.aircraft[1].code
getResult.trips.data.aircraft[1].kind
getResult.trips.data.aircraft[1].name
getResult.trips.data.airport[1].city
getResult.trips.data.airport[1].code
getResult.trips.data.airport[1].kind
getResult.trips.data.airport[1].name
getResult.trips.data.airport[2].city
getResult.trips.data.airport[2].code
getResult.trips.data.airport[2].kind
getResult.trips.data.airport[2].name
getResult.trips.data.carrier[1].code
getResult.trips.data.carrier[1].kind
getResult.trips.data.carrier[1].name
getResult.trips.data.city[1].code
getResult.trips.data.city[1].kind
getResult.trips.data.city[1].name
getResult.trips.data.city[2].code
getResult.trips.data.city[2].kind
getResult.trips.data.city[2].name
getResult.trips.data.kind
getResult.trips.data.tax[1].id
getResult.trips.data.tax[1].kind
getResult.trips.data.tax[1].name
getResult.trips.data.tax[2].id
getResult.trips.data.tax[2].kind
getResult.trips.data.tax[2].name
getResult.trips.data.tax[3].id
getResult.trips.data.tax[3].kind
getResult.trips.data.tax[3].name
getResult.trips.data.tax[4].id
getResult.trips.data.tax[4].kind
getResult.trips.data.tax[4].name
getResult.trips.data.tax[5].id
getResult.trips.data.tax[5].kind
getResult.trips.data.tax[5].name
getResult.trips.data.tax[6].id
getResult.trips.data.tax[6].kind
getResult.trips.data.tax[6].name
getResult.trips.kind
getResult.trips.requestId
getResult.trips.tripOption[1].id
getResult.trips.tripOption[1].kind
getResult.trips.tripOption[1].saletotal
getResult.trips.tripOption[1].pricing[1].basefareTotal
getResult.trips.tripOption[1].pricing[1].fare[1].basiscode
getResult.trips.tripOption[1].pricing[1].fare[1].carrier
getResult.trips.tripOption[1].pricing[1].fare[1].destination
getResult.trips.tripOption[1].pricing[1].fare[1].id
getResult.trips.tripOption[1].pricing[1].fare[1].kind
getResult.trips.tripOption[1].pricing[1].fare[1].origin
getResult.trips.tripOption[1].pricing[1].fareCalculation
getResult.trips.tripOption[1].pricing[1].kind
getResult.trips.tripOption[1].pricing[1].latestTicketingTime
getResult.trips.tripOption[1].pricing[1].passengers.adultCount
getResult.trips.tripOption[1].pricing[1].passengers.kind
getResult.trips.tripOption[1].pricing[1].ptc
getResult.trips.tripOption[1].pricing[1].refundable
getResult.trips.tripOption[1].pricing[1].saleFareTotal
getResult.trips.tripOption[1].pricing[1].saletaxTotal
getResult.trips.tripOption[1].pricing[1].saleTotal
getResult.trips.tripOption[1].pricing[1].segmentPricing[1].fareId
getResult.trips.tripOption[1].pricing[1].segmentPricing[1].kind
getResult.trips.tripOption[1].pricing[1].segmentPricing[1].segmentId
getResult.trips.tripOption[1].pricing[1].tax[1].chargeType
getResult.trips.tripOption[1].pricing[1].tax[1].code
getResult.trips.tripOption[1].pricing[1].tax[1].country
getResult.trips.tripOption[1].pricing[1].tax[1].id
getResult.trips.tripOption[1].pricing[1].tax[1].kind
getResult.trips.tripOption[1].pricing[1].tax[1].salePrice
getResult.trips.tripOption[1].pricing[1].tax[2].chargeType
getResult.trips.tripOption[1].pricing[1].tax[2].code
getResult.trips.tripOption[1].pricing[1].tax[2].country
getResult.trips.tripOption[1].pricing[1].tax[2].id
getResult.trips.tripOption[1].pricing[1].tax[2].kind
getResult.trips.tripOption[1].pricing[1].tax[2].salePrice
getResult.trips.tripOption[1].pricing[1].tax[3].chargeType
getResult.trips.tripOption[1].pricing[1].tax[3].code
getResult.trips.tripOption[1].pricing[1].tax[3].country
getResult.trips.tripOption[1].pricing[1].tax[3].id
getResult.trips.tripOption[1].pricing[1].tax[3].kind
getResult.trips.tripOption[1].pricing[1].tax[3].salePrice
getResult.trips.tripOption[1].pricing[1].tax[4].chargeType
getResult.trips.tripOption[1].pricing[1].tax[4].code
getResult.trips.tripOption[1].pricing[1].tax[4].country
getResult.trips.tripOption[1].pricing[1].tax[4].id
getResult.trips.tripOption[1].pricing[1].tax[4].kind
getResult.trips.tripOption[1].pricing[1].tax[4].salePrice
getResult.trips.tripOption[1].pricing[1].tax[5].chargeType
getResult.trips.tripOption[1].pricing[1].tax[5].code
getResult.trips.tripOption[1].pricing[1].tax[5].id
getResult.trips.tripOption[1].pricing[1].tax[5].kind
getResult.trips.tripOption[1].pricing[1].tax[5].salePrice
getResult.trips.tripOption[1].pricing[1].tax[6].chargeType
getResult.trips.tripOption[1].pricing[1].tax[6].code
getResult.trips.tripOption[1].pricing[1].tax[6].id
getResult.trips.tripOption[1].pricing[1].tax[6].kind
getResult.trips.tripOption[1].pricing[1].tax[6].salePrice
getResult.trips.tripOption[1].saletotal
getResult.trips.tripOption[1].slice[1].duration
getResult.trips.tripOption[1].slice[1].kind
getResult.trips.tripOption[1].slice[1].segment[1].bookingCode
getResult.trips.tripOption[1].slice[1].segment[1].bookingCodeCount
getResult.trips.tripOption[1].slice[1].segment[1].cabin
getResult.trips.tripOption[1].slice[1].segment[1].duration
getResult.trips.tripOption[1].slice[1].segment[1].flight.carrier
getResult.trips.tripOption[1].slice[1].segment[1].flight.number
getResult.trips.tripOption[1].slice[1].segment[1].id
getResult.trips.tripOption[1].slice[1].segment[1].kind
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].aircraft
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].arrivalTime
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].departureTime
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].destination
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].duration
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].id
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].kind
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].meal
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].mileage
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].origin
getResult.trips.tripOption[1].slice[1].segment[1].leg[1].originTerminal
getResult.trips.tripOption[1].slice[1].segment[1].marriedSegmentGroup
Related
I am trying to filter my GET response(JSON) based on a value in a nested JSON array. For eg: In the following JSON i want to filter an JSON array and print the names of cakes using Chocolate as batter.
{
"id": "0001",
"type": "donut",
"name": "Choco Blueberry Cake",
"ppu": 0.55,
"batter":[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" }
]
}
I have tried something like:
List<String> chocolateCakeList =jsonPath.getList("findAll{it.batter.type=='chocolate'}.name");
and
List<String> chocolateCakeList =jsonPath.getList("findAll{it.batter.it.type=='chocolate'}.name");
Both return empty Lists.
Problem
First, if you want to use findAll then the object to be axtract must be an array. Your json is object {}, not an array []. Actually, your nested object batter is an array [].
keyword to search is Chocolate, not chocolate. Case-sensitive is applied here.
Solution
-If your whole response is exactly what you posted, then the path to extract is
String name = jsonPath.getString("name")
-If your response has structrure like this.
[
{
"id": "0001",
"type": "donut",
"name": "Choco Blueberry Cake",
"ppu": 0.55,
"batter": [
{
"id": "1001",
"type": "Regular"
},
{
"id": "1002",
"type": "Chocolate"
},
{
"id": "1003",
"type": "Blueberry"
}
]
},
{
"id": "0002",
"type": "donut",
"name": "Choco Blueberry Cake",
"ppu": 0.55,
"batter": [
{
"id": "1001",
"type": "Regular"
},
{
"id": "1002",
"type": "Chocolate 2"
},
{
"id": "1003",
"type": "Blueberry"
}
]
}
]
Then the extraction is
List<String> list = jsonPath.getList("findAll {it.batter.findAll {it.type == 'Chocolate'}}.name");
How to convert below json to valid json
{
"attribute_id":"r2d2",
"attribute_values":[
WrappedArray( [
5 b1ed5df4a0330a13a3b6f4c,
{
"L0":{
"name":"ENTERTAINMENT",
"id":"20000"
},
"L1":{
"name":"VIDEO GAMES BOOKS AND OTHER MEDIA",
"id":"26000"
},
"L2":{
"name":"MEDIA",
"id":"26001"
},
"L3":{
"name":"BOOKS",
"id":"26100"
},
"L4":{
"name":"BOOKS MISC L4",
"id":"26800"
}
},
PRIORITY_OTHERS,
1536662873016,
26800
] )
],
"bu":"0",
"item_id":"705024754",
"last_updated_by":"QARTH",
"mart":"0",
"published_at":"1536662873017",
"source":"RAMP",
"timestamp":"1536662873016",
"vertical":"0",
"wpid":"7HX1KF1N9W9Y"
}
Valid json should be this
{
"attribute_id": "r2d2",
"attribute_values": [
[{
"L0": {
"name": "ENTERTAINMENT",
"id": "20000"
},
"L1": {
"name": "VIDEO GAMES BOOKS AND OTHER MEDIA",
"id": "26000"
},
"L2": {
"name": "MEDIA",
"id": "26001"
},
"L3": {
"name": "BOOKS",
"id": "26100"
},
"L4": {
"name": "BOOKS MISC L4",
"id": "26800"
}
},
"PRIORITY_OTHERS",
1536662873016,
26800
]
],
"bu": "0",
"item_id": "705024754",
"last_updated_by": "QARTH",
"mart": "0",
"published_at": "1536662873017",
"source": "RAMP",
"timestamp": "1536662873016",
"vertical": "0",
"wpid": "7HX1KF1N9W9Y"
}
Could you please post your sql if this does not answer your question?
Using this url: https://qpx-express-demo.itasoftware.com/ I am making a request to get flight availability from BOM to NYC on a future date.
The JSON response that i receive :
Formatted Response:
Solution# 1 Sale Price: INR31803
Slice 0
KU 302 BOM 2016-01-29T05:50+05:30 KWI 2016-01-29T07:50+03:00
KU 117 KWI 2016-01-29T09:55+03:00 JFK 2016-01-29T16:20-05:00
Unformatted Response:
{
"kind": "qpxexpress#tripOption",
"saleTotal": "INR31803",
"id": "5WAPnfYj8mARdie1jBKphP002",
"slice": [
{
"kind": "qpxexpress#sliceInfo",
"duration": 1260,
"segment": [
{
"kind": "qpxexpress#segmentInfo",
"duration": 270,
"flight": {
"carrier": "KU",
"number": "302"
},
"id": "G9ieitLhcbGEpU6u",
"cabin": "COACH",
"bookingCode": "H",
"bookingCodeCount": 9,
"marriedSegmentGroup": "0",
"leg": [
{
"kind": "qpxexpress#legInfo",
"id": "LRlNO3Gw0UX8y69J",
"aircraft": "777",
"arrivalTime": "2016-01-29T07:50+03:00",
"departureTime": "2016-01-29T05:50+05:30",
"origin": "BOM",
"destination": "KWI",
"originTerminal": "2",
"destinationTerminal": "M",
"duration": 270,
"mileage": 1713,
"meal": "Breakfast",
"secure": true
}
],
"connectionDuration": 125
},
{
"kind": "qpxexpress#segmentInfo",
"duration": 865,
"flight": {
"carrier": "KU",
"number": "117"
},
"id": "GBan4WxY2pcKVHbu",
"cabin": "COACH",
"bookingCode": "H",
"bookingCodeCount": 9,
"marriedSegmentGroup": "1",
"leg": [
{
"kind": "qpxexpress#legInfo",
"id": "L9pmI3XsVZSBhZah",
"aircraft": "777",
"arrivalTime": "2016-01-29T16:20-05:00",
"departureTime": "2016-01-29T09:55+03:00",
"origin": "KWI",
"destination": "JFK",
"originTerminal": "M",
"destinationTerminal": "4",
"duration": 865,
"mileage": 6336,
"meal": "Meal",
"secure": true
}
]
}
]
}
],
"pricing": [
{
"kind": "qpxexpress#pricingInfo",
"fare": [
{
"kind": "qpxexpress#fareInfo",
"id": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
"carrier": "KU",
"origin": "BOM",
"destination": "NYC",
"basisCode": "HLOWIN1"
}
],
"segmentPricing": [
{
"kind": "qpxexpress#segmentPricing",
"fareId": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
"segmentId": "G9ieitLhcbGEpU6u"
},
{
"kind": "qpxexpress#segmentPricing",
"fareId": "A80Fm/pw8E5LRH33c8hjZw/s+BTPU4IxJWOlGXyM1SLM",
"segmentId": "GBan4WxY2pcKVHbu"
}
],
"baseFareTotal": "INR26460",
"saleFareTotal": "INR26460",
"saleTaxTotal": "INR5343",
"saleTotal": "INR31803",
"passengers": {
"kind": "qpxexpress#passengerCounts",
"adultCount": 1
},
"tax": [
{
"kind": "qpxexpress#taxInfo",
"id": "JN_004",
"chargeType": "GOVERNMENT",
"code": "JN",
"country": "IN",
"salePrice": "INR1482"
},
{
"kind": "qpxexpress#taxInfo",
"id": "F2_001",
"chargeType": "GOVERNMENT",
"code": "F2",
"country": "IN",
"salePrice": "INR53"
},
{
"kind": "qpxexpress#taxInfo",
"id": "IN",
"chargeType": "GOVERNMENT",
"code": "IN",
"country": "IN",
"salePrice": "INR627"
},
{
"kind": "qpxexpress#taxInfo",
"id": "YM_001",
"chargeType": "GOVERNMENT",
"code": "YM",
"country": "IN",
"salePrice": "INR687"
},
{
"kind": "qpxexpress#taxInfo",
"id": "WO_001",
"chargeType": "GOVERNMENT",
"code": "WO",
"country": "IN",
"salePrice": "INR149"
},
{
"kind": "qpxexpress#taxInfo",
"id": "US_002",
"chargeType": "GOVERNMENT",
"code": "US",
"country": "US",
"salePrice": "INR1190"
},
{
"kind": "qpxexpress#taxInfo",
"id": "YX_001",
"chargeType": "GOVERNMENT",
"code": "YX",
"country": "KW",
"salePrice": "INR54"
},
{
"kind": "qpxexpress#taxInfo",
"id": "YC",
"chargeType": "GOVERNMENT",
"code": "YC",
"country": "US",
"salePrice": "INR368"
},
{
"kind": "qpxexpress#taxInfo",
"id": "XY",
"chargeType": "GOVERNMENT",
"code": "XY",
"country": "US",
"salePrice": "INR468"
},
{
"kind": "qpxexpress#taxInfo",
"id": "XA",
"chargeType": "GOVERNMENT",
"code": "XA",
"country": "US",
"salePrice": "INR265"
}
],
"fareCalculation": "BOM KU X/KWI KU NYC 397.64HLOWIN1 NUC 397.64 END ROE 66.541160 FARE INR 26460 XT 53F2 627IN 1482JN 149WO 687YM 54YX 368YC 468XY 265XA 1190US",
"latestTicketingTime": "2016-01-28T19:19-05:00",
"ptc": "ADT",
"refundable": true
}
From the response it is inferred that there are two segments, one with KU 302 and other with KU 117. How can i get per segment (per flight) info from the response?
I'm using the APIs in C#, if you install the Json.NET NuGet package, you can then get the response and deserialize it with:
JsonConvert.DeserializeObject<Response>(jsonString);
To build the Response object you can use an online Json to C# class builder (Google it and you'll find it immediately), or you can use dynamic objects.
Once you have the deserialized responde, you can just use LINQ to filter the informations:
from r in response where <filters> select r.segment // Or specific data.
All this assuming you want to use C#.
I want to index & search nested json in solr. Here is my json code
{
"id": "44444",
"headline": "testing US",
"generaltags": [
{
"type": "person",
"name": "Jayalalitha",
"relevance": "0.334",
"count": 1
},
{
"type": "person",
"name": "Kumar",
"relevance": "0.234",
"count": 1
}
],
"socialtags": {
"type": "SocialTag",
"name": "US",
"importance": 2
},
"topic": {
"type": "Topic",
"name": "US",
"score": "0.936"
}
}
When I try to Index, I'm getting the error "Error parsing JSON field value. Unexpected OBJECT_START"
When we tried to use Multivalued Field & index, we couldn't able to search using the multivalued field? Its returning "Undefined Field"
Also Please advice if I need to do any changes in schema.xml file?
You are nesting child documents within your document. You need to use the proper syntax for nested child documents in JSON:
[
{
"id": "1",
"title": "Solr adds block join support",
"content_type": "parentDocument",
"_childDocuments_": [
{
"id": "2",
"comments": "SolrCloud supports it too!"
}
]
},
{
"id": "3",
"title": "Lucene and Solr 4.5 is out",
"content_type": "parentDocument",
"_childDocuments_": [
{
"id": "4",
"comments": "Lots of new features"
}
]
}
]
Have a look at this article which describes JSON child documents and block joins.
Using the format mentioned by #qux you will face "Expected: OBJECT_START but got ARRAY_START at [16]",
"code": 400
as when JSON starting with [....] will parsed as a JSON array
{
"id": "44444",
"headline": "testing US",
"generaltags": [
{
"type": "person",
"name": "Jayalalitha",
"relevance": "0.334",
"count": 1
},
{
"type": "person",
"name": "Kumar",
"relevance": "0.234",
"count": 1
}
],
"socialtags": {
"type": "SocialTag",
"name": "US",
"importance": 2
},
"topic": {
"type": "Topic",
"name": "US",
"score": "0.936"
}
}
The above format is correct.
Regarding searching. Kindly use the index to search for the elements of the JSON array.
The workaround for this can be keeping the whole JSON object inside other JSON object and the indexing it
I was suggesting to keep the whole data inside another JSON object. You can try the following way
{
"data": [
{
"id": "44444",
"headline": "testing US",
"generaltags": [
{
"type": "person",
"name": "Jayalalitha",
"relevance": "0.334",
"count": 1
},
{
"type": "person",
"name": "Kumar",
"relevance": "0.234",
"count": 1
}
],
"socialtags": {
"type": "SocialTag",
"name": "US",
"importance": 2
},
"topic": {
"type": "Topic",
"name": "US",
"score": "0.936"
}
}
]
}
see the syntax in http://yonik.com/solr-nested-objects/
$ curl http://localhost:8983/solr/demo/update?commitWithin=3000 -d '
[
{id : book1, type_s:book, title_t : "The Way of Kings", author_s : "Brandon Sanderson",
cat_s:fantasy, pubyear_i:2010, publisher_s:Tor,
_childDocuments_ : [
{ id: book1_c1, type_s:review, review_dt:"2015-01-03T14:30:00Z",
stars_i:5, author_s:yonik,
comment_t:"A great start to what looks like an epic series!"
}
,
{ id: book1_c2, type_s:review, review_dt:"2014-03-15T12:00:00Z",
stars_i:3, author_s:dan,
comment_t:"This book was too long."
}
]
}
]'
supported from solr 5.3
I have code from example 1.js (link give below)
here that variable json contains json data,instead of specify this data in this file i want to refer from another file which will help me making the protovis treemap dynamic.
I am new to json i don't know how to refer store json data from another file into a variable
full code is available in this link http://thejit.org/static/v20/Jit/Examples/Treemap/example1.js
function init(){
//init data
var json = {
"children": [
{
"children": [
{
"children": [],
"data": {
"playcount": "276",
"$color": "#8E7032",
"image": "http://userserve-ak.last.fm/serve/300x300/11403219.jpg",
"$area": 276
},
"id": "album-Thirteenth Step",
"name": "Thirteenth Step"
},
{
"children": [],
"data": {
"playcount": "271",
"$color": "#906E32",
"image": "http://userserve-ak.last.fm/serve/300x300/11393921.jpg",
"$area": 271
},
"id": "album-Mer De Noms",
"name": "Mer De Noms"
}
],
"data": {
"playcount": 547,
"$area": 547
},
"id": "artist_A Perfect Circle",
"name": "A Perfect Circle"
},
{
"children": [
{
"children": [],
"data": {
"playcount": "209",
"$color": "#AA5532",
"image": "http://userserve-ak.last.fm/serve/300x300/32349839.jpg",
"$area": 209
},
"id": "album-Above",
"name": "Above"
}
],
"data": {
"playcount": 209,
"$area": 209
},
"id": "artist_Mad Season",
"name": "Mad Season"
}
......