How to filter keys in record_path in pandas json_normalize method? - json

I have a large json/dict:
{
"vegetarian": false,
"vegan": false,
"glutenFree": false,
"dairyFree": false,
"veryHealthy": false,
"cheap": false,
"veryPopular": false,
"sustainable": false,
"weightWatcherSmartPoints": 14,
"gaps": "no",
"lowFodmap": false,
"aggregateLikes": 1,
"spoonacularScore": 57.0,
"healthScore": 21.0,
"creditsText": "BBC Good Food",
"sourceName": "BBC Good Food",
"pricePerServing": 231.2,
"id": 1089577,
"title": "Hungarian Goulash Stew",
"readyInMinutes": 120,
"servings": 4,
"sourceUrl": "https://www.bbcgoodfood.com/recipes/1107653/hungarian-goulash-stew",
"image": "https://spoonacular.com/recipeImages/1089577-312x231.jpg",
"imageType": "jpg",
"nutrition": {
"nutrients": [
{
"name": "Calories",
"title": "Calories",
"amount": 323.18,
"unit": "kcal",
"percentOfDailyNeeds": 16.16
},
{
"name": "Fat",
"title": "Fat",
"amount": 15.14,
"unit": "g",
"percentOfDailyNeeds": 23.3
},
{
"name": "Saturated Fat",
"title": "Saturated Fat",
"amount": 4.43,
"unit": "g",
"percentOfDailyNeeds": 27.69
},
{
"name": "Carbohydrates",
"title": "Carbohydrates",
"amount": 38.95,
"unit": "g",
"percentOfDailyNeeds": 12.98
},
{
"name": "Net Carbohydrates",
"title": "Net Carbohydrates",
"amount": 34.64,
"unit": "g",
"percentOfDailyNeeds": 12.6
},
{
"name": "Sugar",
"title": "Sugar",
"amount": 11.27,
"unit": "g",
"percentOfDailyNeeds": 12.52
},
{
"name": "Cholesterol",
"title": "Cholesterol",
"amount": 102.67,
"unit": "mg",
"percentOfDailyNeeds": 34.22
},
{
"name": "Sodium",
"title": "Sodium",
"amount": 1864.24,
"unit": "mg",
"percentOfDailyNeeds": 81.05
},
{
"name": "Protein",
"title": "Protein",
"amount": 10.3,
"unit": "g",
"percentOfDailyNeeds": 20.6
},
{
"name": "Vitamin A",
"title": "Vitamin A",
"amount": 3866.5,
"unit": "IU",
"percentOfDailyNeeds": 77.33
},
{
"name": "Vitamin E",
"title": "Vitamin E",
"amount": 3.49,
"unit": "mg",
"percentOfDailyNeeds": 23.3
},
{
"name": "Selenium",
"title": "Selenium",
"amount": 13.41,
"unit": "µg",
"percentOfDailyNeeds": 19.16
},
{
"name": "Manganese",
"title": "Manganese",
"amount": 0.38,
"unit": "mg",
"percentOfDailyNeeds": 18.83
},
{
"name": "Iron",
"title": "Iron",
"amount": 3.19,
"unit": "mg",
"percentOfDailyNeeds": 17.74
},
{
"name": "Vitamin B2",
"title": "Vitamin B2",
"amount": 0.3,
"unit": "mg",
"percentOfDailyNeeds": 17.54
},
{
"name": "Fiber",
"title": "Fiber",
"amount": 4.31,
"unit": "g",
"percentOfDailyNeeds": 17.22
},
{
"name": "Folate",
"title": "Folate",
"amount": 61.04,
"unit": "µg",
"percentOfDailyNeeds": 15.26
},
{
"name": "Vitamin B6",
"title": "Vitamin B6",
"amount": 0.3,
"unit": "mg",
"percentOfDailyNeeds": 14.9
},
{
"name": "Vitamin B1",
"title": "Vitamin B1",
"amount": 0.21,
"unit": "mg",
"percentOfDailyNeeds": 13.72
},
{
"name": "Vitamin K",
"title": "Vitamin K",
"amount": 13.78,
"unit": "µg",
"percentOfDailyNeeds": 13.13
},
{
"name": "Potassium",
"title": "Potassium",
"amount": 407.99,
"unit": "mg",
"percentOfDailyNeeds": 11.66
},
{
"name": "Vitamin C",
"title": "Vitamin C",
"amount": 9.53,
"unit": "mg",
"percentOfDailyNeeds": 11.56
},
{
"name": "Phosphorus",
"title": "Phosphorus",
"amount": 111.88,
"unit": "mg",
"percentOfDailyNeeds": 11.19
},
{
"name": "Vitamin B3",
"title": "Vitamin B3",
"amount": 2.01,
"unit": "mg",
"percentOfDailyNeeds": 10.05
},
{
"name": "Copper",
"title": "Copper",
"amount": 0.15,
"unit": "mg",
"percentOfDailyNeeds": 7.53
},
{
"name": "Magnesium",
"title": "Magnesium",
"amount": 29.73,
"unit": "mg",
"percentOfDailyNeeds": 7.43
},
{
"name": "Vitamin B5",
"title": "Vitamin B5",
"amount": 0.69,
"unit": "mg",
"percentOfDailyNeeds": 6.95
},
{
"name": "Zinc",
"title": "Zinc",
"amount": 0.89,
"unit": "mg",
"percentOfDailyNeeds": 5.93
},
{
"name": "Calcium",
"title": "Calcium",
"amount": 58.6,
"unit": "mg",
"percentOfDailyNeeds": 5.86
},
{
"name": "Vitamin B12",
"title": "Vitamin B12",
"amount": 0.2,
"unit": "µg",
"percentOfDailyNeeds": 3.3
},
{
"name": "Vitamin D",
"title": "Vitamin D",
"amount": 0.46,
"unit": "µg",
"percentOfDailyNeeds": 3.06
}
]
}
I would like to keep the id, readyInMinutes and title keys + nutrition, the issue is that I need the nutrition to be parsed (because it's a list of dicts).
I am trying panda's pd.json_normalize function to do this:
keys = ['id', 'title', 'readyInMinutes']
pd.json_normalize(results[0], meta = keys, record_path=['nutrition',['nutrients']], record_prefix='nutrients.')
But if I need to filter which keys I want inside the record_path? For example only title and amount?
Please instruct how can I configure it.

To parse JSON data you can use JMESPath library.
JMESPath search syntax:
search(<jmespath expr>, <JSON document>)
In your case the JMESPath expression will be this:
{id: id, readyInMinutes:readyInMinutes, title: title, nutrition: {nutrients: nutrition.nutrients[*].{title: title, amount: amount}}}
Output:
{
"id": 1089577,
"readyInMinutes": 120,
"title": "Hungarian Goulash Stew",
"nutrition": {
"nutrients": [
{
"title": "Calories",
"amount": 323.18
},
{
"title": "Fat",
"amount": 15.14
},
{
"title": "Saturated Fat",
"amount": 4.43
},
{
"title": "Carbohydrates",
"amount": 38.95
},
{
"title": "Net Carbohydrates",
"amount": 34.64
},
{
"title": "Sugar",
"amount": 11.27
},
{
"title": "Cholesterol",
"amount": 102.67
},
{
"title": "Sodium",
"amount": 1864.24
},
{
"title": "Protein",
"amount": 10.3
},
{
"title": "Vitamin A",
"amount": 3866.5
},
{
"title": "Vitamin E",
"amount": 3.49
},
{
"title": "Selenium",
"amount": 13.41
},
{
"title": "Manganese",
"amount": 0.38
},
{
"title": "Iron",
"amount": 3.19
},
{
"title": "Vitamin B2",
"amount": 0.3
},
{
"title": "Fiber",
"amount": 4.31
},
{
"title": "Folate",
"amount": 61.04
},
{
"title": "Vitamin B6",
"amount": 0.3
},
{
"title": "Vitamin B1",
"amount": 0.21
},
{
"title": "Vitamin K",
"amount": 13.78
},
{
"title": "Potassium",
"amount": 407.99
},
{
"title": "Vitamin C",
"amount": 9.53
},
{
"title": "Phosphorus",
"amount": 111.88
},
{
"title": "Vitamin B3",
"amount": 2.01
},
{
"title": "Copper",
"amount": 0.15
},
{
"title": "Magnesium",
"amount": 29.73
},
{
"title": "Vitamin B5",
"amount": 0.69
},
{
"title": "Zinc",
"amount": 0.89
},
{
"title": "Calcium",
"amount": 58.6
},
{
"title": "Vitamin B12",
"amount": 0.2
},
{
"title": "Vitamin D",
"amount": 0.46
}
]
}
}

Related

Extract Specific Values in a JSON String using XSLT

I need help in getting the specific keys and its dynamic values stored in JSON string in an XML element.
Below is an example of the JSON data:
<data attribute-id="item">
[
{
"item_name": "item1",
"quantity": 1,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 34.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 123.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
},
"price": {
"currency": "CAD",
"amount": 123,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
},
{
"item_name": "item2",
"quantity": 2,
"key": "subtotal",
"price": {
"currency": "CAD",
"amount": 14343.75,
"label": "320.088,75 CAD",
"base": {
"amount": 90.75,
"currency": "USD",
"label": "US$90.75"
}
},
"total": {
"currency": "CAD",
"amount": 3431.5,
"label": "640.177,50 CAD",
"base": {
"amount": 181.5,
"currency": "USD",
"label": "US$181.50"
}
},
"included": [
{
"key": "item_price",
"total": {
"currency": "CAD",
"amount": 753150,
"label": "753.150,00 CAD",
"base": {
"amount": 213.52,
"currency": "USD",
"label": "US$213.52"
}
},
"price": {
"currency": "CAD",
"amount": 376575,
"label": "376.575,00 CAD",
"base": {
"amount": 106.76,
"currency": "USD",
"label": "US$106.76"
}
}
},
{
"key": "rounding",
"total": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
},
"price": {
"currency": "CAD",
"amount": 0,
"label": "0,00 CAD",
"base": {
"amount": 0,
"currency": "USD",
"label": "US$0.00"
}
}
},
{
"key": "item_discount",
"total": {
"currency": "CAD",
"amount": -112972.5,
"label": "-112.972,50 CAD",
"base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
},
"price": {
"currency": "CAD",
"amount": -56486.25,
"label": "-56.486,25 CAD",
"base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
}
}
}
]
}
]
</data>
My Expected output is to get key "item_name" and its dynamic value and key "amount" and its dynamic value (key->discount (base array)). Below is the expected output from the given JSON string:
"item_name": "item1","base": {
"amount": -16.01,
"currency": "USD",
"label": "-US$16.01"
},
"item_name": "item2","base": {
"amount": -32.02,
"currency": "USD",
"label": "-US$32.02"
}
Any help is greatly appreciated!

How to group flight segments/legs in Bargain Finder Max?

I am trying to search for flights between two places in Sabre using BargainFindermax API. The API provides me with a list of all flights. However, there is no direct relation to which of the flights are linked.
For example, I searched for flights between BLR > LCY. The response I got included flights for AMS > LCY, BLR > DEL, BLR > DEL, DEL > AMS, AMS > LCY.
From this, I can construct the following route BLR > DEL > AMS > LCY. But there are two flights for BLR > DEL and AMS > LCY.
How can I identify which of these flights are related?
Here is the complete JSON response,
{
"groupedItineraryResponse": {
"version": "5.2.0",
"messages": [
{
"severity": "Info",
"type": "WORKERTHREAD",
"code": "TRANSACTIONID",
"text": "2074398531853061390"
},
{
"severity": "Info",
"type": "SERVER",
"code": "ASE032LPSCIL9UM.IDM.SGDCCERT.SABRE.COM",
"text": "27036"
},
{
"severity": "Info",
"type": "DRE",
"code": "RULEID",
"text": "17203"
},
{
"severity": "Info",
"type": "DEFAULT",
"code": "RULEID",
"text": "25238"
}
],
"statistics": {
"itineraryCount": 2
},
"scheduleDescs": [
{
"id": 1,
"frequency": "*MTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 257,
"departure": {
"airport": "AMS",
"city": "AMS",
"country": "NL",
"time": "08:45:00+02:00"
},
"arrival": {
"airport": "LCY",
"city": "LON",
"country": "GB",
"time": "08:50:00+01:00"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 985,
"operating": "KL",
"operatingFlightNumber": 985,
"codeShared": "/KLM CITYHOPPER",
"equipment": {
"code": "E90",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
},
{
"id": 2,
"trafficRestriction": "G",
"frequency": "SMTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 1058,
"departure": {
"airport": "BLR",
"city": "BLR",
"country": "IN",
"time": "19:50:00+05:30"
},
"arrival": {
"airport": "DEL",
"city": "DEL",
"country": "IN",
"time": "22:50:00+05:30",
"terminal": "3"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 3798,
"operating": "9W",
"operatingFlightNumber": 812,
"disclosure": "9W",
"equipment": {
"code": "73H",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
},
{
"id": 3,
"trafficRestriction": "G",
"frequency": "SMTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 1058,
"departure": {
"airport": "BLR",
"city": "BLR",
"country": "IN",
"time": "18:55:00+05:30"
},
"arrival": {
"airport": "DEL",
"city": "DEL",
"country": "IN",
"time": "22:00:00+05:30",
"terminal": "3"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 3703,
"operating": "9W",
"operatingFlightNumber": 833,
"disclosure": "9W",
"equipment": {
"code": "738",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
},
{
"id": 4,
"frequency": "*M**T**",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 3961,
"departure": {
"airport": "DEL",
"city": "DEL",
"country": "IN",
"time": "02:10:00+05:30",
"terminal": "3"
},
"arrival": {
"airport": "AMS",
"city": "AMS",
"country": "NL",
"time": "07:40:00+02:00"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 3817,
"operating": "9W",
"operatingFlightNumber": 234,
"disclosure": "9W",
"equipment": {
"code": "333",
"typeForFirstLeg": "W",
"typeForLastLeg": "W"
}
}
},
{
"id": 5,
"frequency": "*MTWTFS",
"stopCount": 0,
"eTicketable": true,
"totalMilesFlown": 257,
"departure": {
"airport": "AMS",
"city": "AMS",
"country": "NL",
"time": "09:25:00+02:00"
},
"arrival": {
"airport": "LCY",
"city": "LON",
"country": "GB",
"time": "09:30:00+01:00"
},
"carrier": {
"marketing": "KL",
"marketingFlightNumber": 987,
"operating": "KL",
"operatingFlightNumber": 987,
"codeShared": "/KLM CITYHOPPER",
"equipment": {
"code": "E90",
"typeForFirstLeg": "N",
"typeForLastLeg": "N"
}
}
}
],
"taxDescs": [
{
"id": 1,
"code": "YRI",
"amount": 160,
"currency": "USD",
"description": "SERVICE FEE - CARRIER-IMPOSED MISC",
"publishedAmount": 160,
"publishedCurrency": "USD",
"station": "DEL"
},
{
"id": 2,
"code": "YQI",
"amount": 13.3,
"currency": "USD",
"description": "SERVICE FEE - INSURANCE",
"publishedAmount": 925,
"publishedCurrency": "INR",
"station": "BLR"
},
{
"id": 3,
"code": "WO",
"amount": 3.8,
"currency": "USD",
"description": "PASSENGER SERVICE FEE",
"publishedAmount": 3.8,
"publishedCurrency": "USD",
"station": "BLR",
"country": "IN"
},
{
"id": 4,
"code": "K38",
"amount": 11.5,
"currency": "USD",
"description": "GOODS AND SERVICE TAX INTERIM DOMESTIC AND INTERNATIONAL",
"publishedAmount": 799,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
},
{
"id": 5,
"code": "CJ",
"amount": 7.4,
"currency": "USD",
"description": "SECURITY SERVICE CHARGE",
"publishedAmount": 6.5,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 6,
"code": "RN",
"amount": 7.3,
"currency": "USD",
"description": "PASSENGER SERVICE CHARGE",
"publishedAmount": 6.4,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 7,
"code": "IN",
"amount": 5.2,
"currency": "USD",
"description": "USER DEVELOPMENT FEE DEPARTURES",
"publishedAmount": 362,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
}
],
"taxSummaryDescs": [
{
"id": 1,
"code": "YRI",
"amount": 160,
"currency": "USD",
"description": "SERVICE FEE - CARRIER-IMPOSED MISC",
"publishedAmount": 160,
"publishedCurrency": "USD",
"station": "DEL"
},
{
"id": 2,
"code": "YQI",
"amount": 13.3,
"currency": "USD",
"description": "SERVICE FEE - INSURANCE",
"publishedAmount": 925,
"publishedCurrency": "INR",
"station": "BLR"
},
{
"id": 3,
"code": "WO",
"amount": 3.8,
"currency": "USD",
"description": "PASSENGER SERVICE FEE",
"publishedAmount": 3.8,
"publishedCurrency": "USD",
"station": "BLR",
"country": "IN"
},
{
"id": 4,
"code": "K38",
"amount": 11.5,
"currency": "USD",
"description": "GOODS AND SERVICE TAX INTERIM DOMESTIC AND INTERNATIONAL",
"publishedAmount": 0.05,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
},
{
"id": 5,
"code": "CJ",
"amount": 7.4,
"currency": "USD",
"description": "SECURITY SERVICE CHARGE",
"publishedAmount": 6.5,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 6,
"code": "RN",
"amount": 7.3,
"currency": "USD",
"description": "PASSENGER SERVICE CHARGE",
"publishedAmount": 6.4,
"publishedCurrency": "EUR",
"station": "AMS",
"country": "NL"
},
{
"id": 7,
"code": "IN",
"amount": 5.2,
"currency": "USD",
"description": "USER DEVELOPMENT FEE DEPARTURES",
"publishedAmount": 362,
"publishedCurrency": "INR",
"station": "BLR",
"country": "IN"
}
],
"fareComponentDescs": [
{
"id": 1,
"governingCarrier": "KL",
"fareAmount": 24.65,
"fareCurrency": "INR",
"fareBasisCode": "XPLWIA",
"farePassengerType": "ADT",
"publishedFareAmount": 1717,
"oneWayFare": true,
"directionality": "FROM",
"direction": "EH",
"notValidBefore": "2019-07-21",
"notValidAfter": "2019-07-21",
"applicablePricingCategories": "4 5 6 7 8 10 12 16 18",
"vendorCode": "ATP",
"fareTypeBitmap": "00",
"fareType": "PRU",
"fareTariff": "4",
"fareRule": "INPL",
"segments": [
{
"segment": {
"surcharges": [
{
"amount": 28.71,
"currency": "NUC",
"description": "MISCELLANEOUS/OTHER",
"type": "Q"
}
]
}
},
{
"segment": {}
},
{
"segment": {}
}
]
}
],
"validatingCarrierDescs": [
{
"id": 1,
"settlementMethod": "ARC",
"newVcxProcess": true,
"default": {
"code": "DL"
}
}
],
"baggageAllowanceDescs": [
{
"id": 1,
"pieceCount": 1
}
],
"legDescs": [
{
"id": 1,
"schedules": [
{
"ref": 2
},
{
"ref": 4,
"departureDateAdjustment": 1
},
{
"ref": 5,
"departureDateAdjustment": 1
}
]
},
{
"id": 2,
"schedules": [
{
"ref": 3
},
{
"ref": 4,
"departureDateAdjustment": 1
},
{
"ref": 1,
"departureDateAdjustment": 1
}
]
}
],
"itineraryGroups": [
{
"groupDescription": {
"legDescriptions": [
{
"departureDate": "2019-07-21",
"departureLocation": "BLR",
"arrivalLocation": "LCY"
}
]
},
"itineraries": [
{
"id": 1,
"pricingSource": "ADVJR1",
"legs": [
{
"ref": 2
}
],
"pricingInformation": [
{
"pricingSubsource": "MIP",
"fare": {
"validatingCarrierCode": "DL",
"vita": true,
"eTicketable": true,
"lastTicketDate": "2019-07-05",
"governingCarriers": "KL",
"passengerInfoList": [
{
"passengerInfo": {
"passengerType": "ADT",
"passengerNumber": 1,
"nonRefundable": true,
"fareComponents": [
{
"ref": 1,
"segments": [
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "D",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "RB",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "L",
"cabinCode": "Y",
"mealCode": "M",
"seatsAvailable": 9,
"availabilityBreak": true
}
}
]
}
],
"taxes": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 7
},
{
"ref": 4
},
{
"ref": 3
},
{
"ref": 5
},
{
"ref": 6
}
],
"taxSummaries": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 3
},
{
"ref": 4
},
{
"ref": 7
},
{
"ref": 5
},
{
"ref": 6
}
],
"currencyConversion": {
"from": "INR",
"to": "USD",
"exchangeRateUsed": 0.01442679
},
"fareMessages": [
{
"type": "N",
"code": "0",
"carrier": "KL",
"info": "FARE RESTRICTIONS APPLY/CARRIER RESTRICTIONS APPLY"
},
{
"type": "W",
"code": "0",
"info": "VALIDATING CARRIER - DL PER GSA AGREEMENT WITH KL"
}
],
"passengerTotalFare": {
"totalFare": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"equivalentAmount": 56,
"equivalentCurrency": "USD",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"commissionPercentage": 0,
"commissionAmount": 0,
"exchangeRateOne": 69.651352
},
"baggageInformation": [
{
"provisionType": "A",
"airlineCode": "KL",
"segments": [
{
"id": 0
},
{
"id": 1
},
{
"id": 2
}
],
"allowance": {
"ref": 1
}
}
]
}
}
],
"totalFare": {
"totalPrice": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"equivalentAmount": 56,
"equivalentCurrency": "USD"
},
"validatingCarriers": [
{
"ref": 1
}
]
}
}
],
"diversitySwapper": {
"weighedPrice": 409.855
}
},
{
"id": 2,
"pricingSource": "ADVJR1",
"legs": [
{
"ref": 1
}
],
"pricingInformation": [
{
"pricingSubsource": "MIP",
"fare": {
"validatingCarrierCode": "DL",
"vita": true,
"eTicketable": true,
"lastTicketDate": "2019-07-05",
"governingCarriers": "KL",
"passengerInfoList": [
{
"passengerInfo": {
"passengerType": "ADT",
"passengerNumber": 1,
"nonRefundable": true,
"fareComponents": [
{
"ref": 1,
"segments": [
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "D",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "X",
"cabinCode": "Y",
"mealCode": "RB",
"seatsAvailable": 9
}
},
{
"segment": {
"bookingCode": "L",
"cabinCode": "Y",
"mealCode": "M",
"seatsAvailable": 9,
"availabilityBreak": true
}
}
]
}
],
"taxes": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 7
},
{
"ref": 4
},
{
"ref": 3
},
{
"ref": 5
},
{
"ref": 6
}
],
"taxSummaries": [
{
"ref": 2
},
{
"ref": 1
},
{
"ref": 3
},
{
"ref": 4
},
{
"ref": 7
},
{
"ref": 5
},
{
"ref": 6
}
],
"currencyConversion": {
"from": "INR",
"to": "USD",
"exchangeRateUsed": 0.01442679
},
"fareMessages": [
{
"type": "N",
"code": "0",
"carrier": "KL",
"info": "FARE RESTRICTIONS APPLY/CARRIER RESTRICTIONS APPLY"
},
{
"type": "W",
"code": "0",
"info": "VALIDATING CARRIER - DL PER GSA AGREEMENT WITH KL"
}
],
"passengerTotalFare": {
"totalFare": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"equivalentAmount": 56,
"equivalentCurrency": "USD",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"commissionPercentage": 0,
"commissionAmount": 0,
"exchangeRateOne": 69.651352
},
"baggageInformation": [
{
"provisionType": "A",
"airlineCode": "KL",
"segments": [
{
"id": 0
},
{
"id": 1
},
{
"id": 2
}
],
"allowance": {
"ref": 1
}
}
]
}
}
],
"totalFare": {
"totalPrice": 264.5,
"totalTaxAmount": 208.5,
"currency": "USD",
"baseFareAmount": 3875,
"baseFareCurrency": "INR",
"constructionAmount": 55.59,
"constructionCurrency": "NUC",
"equivalentAmount": 56,
"equivalentCurrency": "USD"
},
"validatingCarriers": [
{
"ref": 1
}
]
}
}
],
"diversitySwapper": {
"weighedPrice": 367.631
}
}
]
}
]
}
}
You have to use legDescs list to connect your segments, and use those "ref" values.
For example:
{
"id": 2,
"schedules": [
{
"ref": 3
},
{
"departureDateAdjustment": 1,
"ref": 4
},
{
"departureDateAdjustment": 1,
"ref": 1
}
]
}
means, your flight with ID = 2 contains 3 segments, with id 3 - 4 and 1. When you search numbered segments in "scheduleDescs" object, you can see routes are:
BLR - DEL
DEL - AMS
AMS - LCY
and as you can see you got the BLR - LCY flight.

How to get a json key that contains a specific string with jq?

I have a json data like this:
{
"success": true,
"module": {
"endpoint": {
"mode": "pc",
"protocolVersion": "2.0"
},
"reload": true,
"data": {
"leftContainer_CL": {
"id": "CL",
"tag": "leftContainer",
"fields": {
"css": {
"floatPosition": "left",
"width": "788px"
},
"tag": "leftContainer"
},
"type": "container"
},
"container_C": {
"id": "C",
"tag": "container",
"fields": {
"css": {
"marginTop": "12px"
},
"tag": "container"
},
"type": "container"
},
"delivery_dfdaf8a8a": {
"id": "dfdaf8a8a",
"tag": "delivery",
"fields": {
"selectPos": "right",
"deliveryBy": {
"text": "Disediakan oleh",
"poster": "ALL ITEM STORE"
},
"options": [
{
"highlight": false,
"deliveryId": "STANDARD",
"bgColor": "#fafafa",
"price": "Rp18.900",
"disable": false,
"reachTime": "Dapatkan pada\n 3-4 Apr 2018",
"liveUp": false,
"selected": true
}
],
"style": "bar"
},
"type": "biz"
},
"rightContainer_CR": {
"id": "CR",
"tag": "rightContainer",
"fields": {
"css": {
"floatPosition": "right",
"width": "388px"
},
"tag": "rightContainer"
},
"type": "container"
},
"delivery_d43597338a": {
"id": "d43597338a",
"tag": "delivery",
"fields": {
"selectPos": "right",
"deliveryBy": {
"text": "Disediakan oleh",
"poster": "incredible accessories hp"
},
"options": [
{
"highlight": false,
"deliveryId": "STANDARD",
"bgColor": "#fafafa",
"price": "Rp37.800",
"disable": false,
"reachTime": "Dapatkan pada\n 3-4 Apr 2018",
"liveUp": false,
"selected": true
}
],
"style": "bar"
},
"type": "biz"
},
"orderSummary_6": {
"id": "6",
"tag": "orderSummary",
"fields": {
"isOpen": "false",
"summarys": [
{
"tail": "(3 barang)",
"title": "Subtotal",
"value": "Rp23.557"
},
{
"title": "Biaya pengiriman",
"value": "Rp56.700"
}
],
"title": "Ringkasan Pesanan\r\n"
},
"type": "biz"
},
"root_0": {
"id": "0",
"tag": "root",
"fields": {
"count": 3,
"title": "Troli belanja Saya"
},
"type": "root"
},
"item_i77997d6b": {
"id": "i77997d6b",
"tag": "item",
"fields": {
"img": "https://id-live.slatic.net/original/08c1396908dc240625751b09decb4211.jpg",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "ALL ITEM STORE",
"title": "Case Slim Black Matte Xiaomi Redmi 4A Softcase Black",
"stockTip": {},
"valid": true,
"itemId": "143800088",
"operations": [
"wishlist",
"delete"
],
"sellerId": "100124080",
"price": {
"price": 6000,
"currentPrice": "Rp6.000",
"originPrice": "Rp30.000",
"promotionRatio": "-80%"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Softcase, Hitam",
"productVariant": "SO908ELAAVYY4AANID-72544754",
"brandId": "17818",
"skuId": "157608391"
},
"itemUrl": "https://www.lazada.co.id/products/i143800088-s157608391.html?urlFlag=true&mp=1",
"cartItemId": 2006547819
},
"type": "biz"
},
"location_2": {
"id": "2",
"tag": "location",
"fields": {
"buttonText": "GANTI\r\n",
"editable": true,
"postCode": "",
"style": "casAddress",
"label": "Lokasi",
"title": "Jawa Tengah,Kab. Boyolali,Ampel",
"addressId": "R2388357-R80010396-R80015219"
},
"type": "biz"
},
"voucherInput_7": {
"id": "7",
"tag": "voucherInput",
"fields": {
"buttonText": "GUNAKAN",
"placeHolder": "Masukkan Kode Voucher",
"status": "default"
},
"type": "biz",
"validate": {
"value": [
{
"msg": "Maaf, voucher ini tidak dapat digunakan. Silahkan periksa jika ada kesalahan penulisan",
"regex": "^$|^[ ]{0,5}[A-Za-z0-9~!##%&*()_+?<>{}|-]{1,100}[ ]{0,5}$"
}
]
}
},
"shop_43597338a_s2c": {
"id": "43597338a_s2c",
"tag": "shop",
"fields": {
"badges": [],
"link": "//www.lazada.co.id/shop/incredible-accessories-hp",
"name": "incredible accessories hp"
},
"type": "biz"
},
"item_i7799f86e": {
"id": "i7799f86e",
"tag": "item",
"fields": {
"img": "http://id-live-02.slatic.net/p/2/case-anti-shock-anti-crack-elegant-softcase-for-xiaomi-redmi-5a-white-clear-free-tempered-glass-1273-94487227-9f8ddff53bde3f8de9eb514ba2172361-catalog.jpg",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "incredible accessories hp",
"title": "Case Anti Shock / Anti Crack Elegant Softcase for Xiaomi Redmi 5A - White Clear + Free Tempered Glass",
"stockTip": {},
"valid": true,
"itemId": "160714927",
"operations": [
"wishlist",
"delete"
],
"sellerId": "53631",
"price": {
"price": 13580,
"currentPrice": "Rp13.580",
"originPrice": "Rp25.000",
"promotionRatio": "-46%"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Softcase, Bening",
"productVariant": "SO908ELAB716EPANID-97510528",
"brandId": "17818",
"skuId": "183461134"
},
"itemUrl": "https://www.lazada.co.id/products/i160714927-s183461134.html?urlFlag=true&mp=1",
"cartItemId": 2006579310
},
"type": "biz"
},
"package_p43597338a": {
"id": "p43597338a",
"tag": "package",
"fields": {},
"type": "biz"
},
"listHeader_H": {
"id": "H",
"tag": "listHeader",
"fields": {
"middle": "HARGA",
"left": "3 barang",
"right": "KUANTITAS"
},
"type": "biz"
},
"delivery_3": {
"id": "3",
"tag": "delivery",
"fields": {
"selectPos": "left",
"options": [
{
"highlight": false,
"deliveryId": "STANDARD",
"bgColor": "#fafafa",
"price": "Rp56.700",
"disable": false,
"icon": "https://laz-img-cdn.alicdn.com/tfs/TB1UpyCpfDH8KJjy1XcXXcpdXXa-72-72.png",
"name": "Standar",
"reachTime": "Dapatkan pada\n 3-4 Apr 2018",
"liveUp": false,
"selected": true
}
],
"style": "card",
"title": "Pengiriman yang dipilih"
},
"type": "biz"
},
"orderTotal_8": {
"id": "8",
"tag": "orderTotal",
"fields": {
"button": {
"enable": true,
"text": "LANJUTKAN KE PEMBAYARAN",
"clicked": false
},
"payment": {
"taxTip": "Termasuk PPN, jika berlaku",
"pay": "Rp80.257",
"title": "Total"
}
},
"type": "biz"
},
"shop_fdaf8a8a_s23f9": {
"id": "fdaf8a8a_s23f9",
"tag": "shop",
"fields": {
"badges": [],
"link": "//www.lazada.co.id/shop/all-item-store",
"name": "ALL ITEM STORE"
},
"type": "biz"
},
"floatTips_4": {
"id": "4",
"tag": "floatTips",
"fields": {
"tips": []
},
"type": "biz"
},
"item_i7790e0f9": {
"id": "i7790e0f9",
"tag": "item",
"fields": {
"img": "http://id-live-02.slatic.net/p/2/case-anti-shock-anti-crack-elegant-softcase-for-xiaomi-redmi-note4x-white-clear-8431-85175402-0bec01e88741744ae5461c4b3a4ae160-catalog.jpg",
"quantity": {
"qtyPrefix": "Kuantitas",
"min": 1,
"autoOptions": false,
"quantity": 1,
"max": 5,
"editable": true,
"showIncrDecr": true,
"showOptions": false,
"step": 1
},
"sellerName": "incredible accessories hp",
"title": "Case Anti Shock / Anti Crack Elegant Softcase for Xiaomi Redmi Note 4x - White Clear",
"stockTip": {},
"valid": true,
"itemId": "108849535",
"operations": [
"wishlist",
"delete"
],
"sellerId": "53631",
"price": {
"price": 3977,
"currentPrice": "Rp3.977",
"originPrice": "Rp15.000",
"promotionRatio": "-73%"
},
"restriction": false,
"isGift": false,
"sku": {
"skuText": "Sarung, Bening",
"productVariant": "CA529ELAAC6GUEANID-27304198",
"brandId": "10464",
"skuId": "110628148"
},
"itemUrl": "https://www.lazada.co.id/products/i108849535-s110628148.html?urlFlag=true&mp=1",
"cartItemId": 2005983481
},
"type": "biz"
},
"package_pfdaf8a8a": {
"id": "pfdaf8a8a",
"tag": "package",
"fields": {},
"type": "biz"
}
},
"hierarchy": {
"component": [
"container",
"delivery",
"item",
"shop",
"package",
"listHeader",
"orderSummary",
"leftContainer",
"orderTotal",
"floatTips",
"root",
"location",
"rightContainer",
"voucherInput"
],
"root": "root_0",
"structure": {
"package_p43597338a": [
"delivery_d43597338a",
"shop_43597338a_s2c",
"item_i7799f86e",
"item_i7790e0f9"
],
"leftContainer_CL": [
"delivery_3",
"listHeader_H",
"package_pfdaf8a8a",
"package_p43597338a"
],
"container_C": [
"leftContainer_CL",
"rightContainer_CR"
],
"rightContainer_CR": [
"location_2",
"orderSummary_6"
],
"orderSummary_6": [
"voucherInput_7",
"orderTotal_8"
],
"root_0": [
"container_C",
"floatTips_4"
],
"package_pfdaf8a8a": [
"delivery_dfdaf8a8a",
"shop_fdaf8a8a_s23f9",
"item_i77997d6b"
]
}
},
"linkage": {
"input": [],
"request": [
"voucherInput_7",
"item_i7799f86e",
"delivery_3",
"orderTotal_8",
"item_i7790e0f9",
"location_2",
"item_i77997d6b"
],
"common": {
"compress": true,
"queryParams": "^^$$1afe141216814f45e9fc6dba84d4863d{$_$}H4sIAAAAAAAAAFWU247bRgyGXyXQ9caYGXJOe5fkJmmLot3de4Ez5OwKlSVBklMkQd69lJsNHBgwZIHfz9NPf+t2Wc/DRGN3/61bRtrbvJ67+26p3V230LPoc6V1777fdROd5XGh+vpu05DLJuu7bRuep0OgjrRtf2rYETGfTyN9JabTNfh0nlnG02Xc13k6LbTSeTv9fZH1y1/XZxVbZWJZ3w9ff7xRxXGutA/z9DTs46H6G/1Lb55keqaXu9+pnN68n7/MI43D3bvzIqOKEPMq2/aJNfrBQUrg49uHZIw1kMP/T97ZfPQ3b/sHrUoju+/aoJa8zJNM+/aoDdF+WeXa1TztNEyy9h800jUoDoPFWnMIVHwCMMiWCJ2zgVRX+xw+a2M9aHyMsbpqwcUChTgxeMZqbWzkJXl7G88IPkeARApKMCYQeJNYojCEVPTboMcCmOIvibgxtURXLrRaKGKrWdhHMslkE1ss2TjnCA+ujTPtT8Oy9XgkilVQsgEX2AXJgQ3UZCNb1yKEY1LDLud+iDEbMS0rYwAzx+KbE6JmcgCbs02YJShhyi2TI4eiTAHr0ROiZS0mOteYW9JChZwR+CVPbikce2Ev4HJiJmuab6TJIApIkZo4JFZmlKZb/LmiP66jqzVlEhe5GJEUs/XNk6csxYacDmrY9o9C6rf+oxJAHqAkJMc69RbZu+yBQKxFqTEcxA8r9u5wgagLRISDNuECYjAFk3NYUnU+Htczryr+eDmfSRcUlNEukSyVmqLXeNG9NnWF16RBV95emad5p7FPx5QNGnSUpHDUllsyGINQUKSp78L1Rus/eqb9cmsdgGp1vmpLcKjD1JsNTUGdqmu6olvuxjmlpaa7KV6wtkqU1UimOXA6gIjXk1mH55fbaT8olhJJMhFrrlwxRwuAmK00ELD6+8Dmee9Ndz9dxvGu217mpf9Zb7+5qirZ1YoYOXJlWw1r1Zz1w7kAxKvKlXutVzG4WlFvGUyKxkhB9RNL9ibmmoGTnkJFBT/Pl/oi66dpuex9VMa65LRQ0fRWnDjSZDogFZJkkYL+HfwHDyba3BsFAAA=",
"submitParams": "^^$$f7898231e0216a924bcaa64d213a61ba{$_$}H4sIAAAAAAAAADXMQQrDMAwEwL/oHPSA3PqBUsgLto4bDJJtJPvS4L/XCfS2uwx7UoumKUNoPakK2qeY0ko10EIVR5w5wBqNhTI0bhXhv/kk3aM93NORr4MgcH9OdomiLPhiB9+YtexRuEuzkrnCoM5bf2tqr7vQGD8eVpdVjwAAAA=="
},
"signature": "89dffd9ca23307e603556a4c896e4c56"
}
}
}
With jq I can do this:
[me#linux]$ cat /tmp/json | jq '.module | .data | keys'
[
"container_C",
"delivery_3",
"delivery_d43597338a",
"delivery_dfdaf8a8a",
"floatTips_4",
"item_i7790e0f9",
"item_i77997d6b",
"item_i7799f86e",
"leftContainer_CL",
"listHeader_H",
"location_2",
"orderSummary_6",
"orderTotal_8",
"package_p43597338a",
"package_pfdaf8a8a",
"rightContainer_CR",
"root_0",
"shop_43597338a_s2c",
"shop_fdaf8a8a_s23f9",
"voucherInput_7"
]
I need to get orderTotal_8 but please note that the number 8 is always changing, so it can be orderTotal_10 or orderTotal_3 etc... How can I get this key with pure jq command if possible, without the help of grep / awk ? So the result should be like this orderTotal_8
If you want to form a subarray of items satisfying some condition, just add map(select( CONDITION )) to the pipeline, e.g.
.module | .data | keys | map(select(test("^orderTotal_")))
If you just want a stream of the items matching the condition, then you could first form the stream, and then make the selection:
.module | .data | keys[] | select(test("^orderTotal_"))
For efficiency and other reasons, you might want to consider using keys_unsorted instead of keys.

reactjs - load json object

I have a file data.js:
const sdc = [
{
"Type": "Buy",
"Price": 0.00226752,
"Amount": 55.95995977,
"Total": 0.12689032
},
{
"Type": "Buy",
"Price": 0.00226752,
"Amount": 146.1,
"Total": 0.33128467
},
{
"Type": "Buy",
"Price": 0.00226684,
"Amount": 150,
"Total": 0.340026
},
{
"Type": "Buy",
"Price": 0.00226684,
"Amount": 26.79415765,
"Total": 0.06073806
},
{
"Type": "Buy",
"Price": 0.00226684,
"Amount": 4.25269162,
"Total": 0.00964017
},
{
"Type": "Buy",
"Price": 0.00226659,
"Amount": 25.79415765,
"Total": 0.05846477
},
{
"Type": "Buy",
"Price": 0.00225784,
"Amount": 4.48789501,
"Total": 0.01013294
},
{
"Type": "Buy",
"Price": 0.00226659,
"Amount": 1,
"Total": 0.00226659
},
{
"Type": "Buy",
"Price": 0.00226663,
"Amount": 225,
"Total": 0.50999175
},
{
"Type": "Buy",
"Price": 0.00226662,
"Amount": 113.4736507,
"Total": 0.25720164
},
{
"Type": "Buy",
"Price": 0.00226659,
"Amount": 26.79415765,
"Total": 0.06073136
},
{
"Type": "Buy",
"Price": 0.00226651,
"Amount": 57.98798342,
"Total": 0.13143034
},
{
"Type": "Buy",
"Price": 0.00226649,
"Amount": 40.19123647,
"Total": 0.09109303
},
{
"Type": "Buy",
"Price": 0.00224958,
"Amount": 11.83690383,
"Total": 0.02662806
},
{
"Type": "Sell",
"Price": 0.00241238,
"Amount": 838,
"Total": 2.02157444
},
{
"Type": "Buy",
"Price": 0.00231078,
"Amount": 9.95795791,
"Total": 0.02301064
},
{
"Type": "Sell",
"Price": 0.0025,
"Amount": 4.1999832,
"Total": 0.01049995
},
{
"Type": "Sell",
"Price": 0.0025,
"Amount": 4.99998,
"Total": 0.01249995
},
{
"Type": "Buy",
"Price": 0.00226702,
"Amount": 3.63623022,
"Total": 0.0082434
},
{
"Type": "Buy",
"Price": 0.00226702,
"Amount": 2.14933238,
"Total": 0.00487257
},
{
"Type": "Buy",
"Price": 0.00226702,
"Amount": 15,
"Total": 0.0340053
},
{
"Type": "Buy",
"Price": 0.00226702,
"Amount": 56.80528353,
"Total": 0.12877871
},
{
"Type": "Buy",
"Price": 0.00227634,
"Amount": 76.88367619,
"Total": 0.17501338
},
{
"Type": "Sell",
"Price": 0.0000141,
"Amount": 12444,
"Total": 0.17546011
},
{
"Type": "Buy",
"Price": 0.0000141,
"Amount": 12131.09257,
"Total": 0.1710484
},
{
"Type": "Buy",
"Price": 0.00001409,
"Amount": 344.0847392,
"Total": 0.00484815
},
{
"Type": "Buy",
"Price": 0.00249461,
"Amount": 154.2853438,
"Total": 0.38488176
},
{
"Type": "Buy",
"Price": 0.00249461,
"Amount": 33.72938801,
"Total": 0.08414166
},
{
"Type": "Buy",
"Price": 0.00246953,
"Amount": 340.8737595,
"Total": 0.84179797
},
{
"Type": "Buy",
"Price": 0.00246953,
"Amount": 90.36231511,
"Total": 0.22315244
},
{
"Type": "Buy",
"Price": 0.00246952,
"Amount": 55.17093479,
"Total": 0.13624572
},
{
"Type": "Buy",
"Price": 0.00246764,
"Amount": 5.75660177,
"Total": 0.01420522
},
{
"Type": "Buy",
"Price": 0.00245929,
"Amount": 4.1587629,
"Total": 0.0102276
},
{
"Type": "Sell",
"Price": 0.00252904,
"Amount": 37.42985716,
"Total": 0.0946616
},
{
"Type": "Sell",
"Price": 0.00252904,
"Amount": 0.59310808,
"Total": 0.00149999
},
{
"Type": "Sell",
"Price": 0.00252904,
"Amount": 1.97703476,
"Total": 0.00499999
},
{
"Type": "Sell",
"Price": 0.00252902,
"Amount": 446.0229574,
"Total": 1.12800097
},
{
"Type": "Sell",
"Price": 0.00252903,
"Amount": 1.97704258,
"Total": 0.00499999
},
{
"Type": "Sell",
"Price": 0.00259459,
"Amount": 38.54173491,
"Total": 0.09999999
},
{
"Type": "Sell",
"Price": 0.00259483,
"Amount": 105.9381622,
"Total": 0.27489152
},
{
"Type": "Sell",
"Price": 0.00259484,
"Amount": 0.03853803,
"Total": 0.0001
},
{
"Type": "Sell",
"Price": 0.00259484,
"Amount": 0.03853803,
"Total": 0.0001
},
{
"Type": "Sell",
"Price": 0.00259485,
"Amount": 1.91102375,
"Total": 0.00495881
},
{
"Type": "Sell",
"Price": 0.00259459,
"Amount": 2,
"Total": 0.00518918
},
{
"Type": "Sell",
"Price": 0.00259464,
"Amount": 1.90549392,
"Total": 0.00494407
},
{
"Type": "Sell",
"Price": 0.00259465,
"Amount": 28.65568722,
"Total": 0.07435147
},
{
"Type": "Buy",
"Price": 0.01740491,
"Amount": 0.20683711,
"Total": 0.00359998
},
{
"Type": "Buy",
"Price": 0.00238916,
"Amount": 79.70696671,
"Total": 0.19043269
},
{
"Type": "Buy",
"Price": 0.00237524,
"Amount": 37.90636505,
"Total": 0.09003671
},
{
"Type": "Buy",
"Price": 0.00237524,
"Amount": 2.00494017,
"Total": 0.00476221
},
{
"Type": "Buy",
"Price": 0.00237524,
"Amount": 18.57724489,
"Total": 0.04412541
},
{
"Type": "Sell",
"Price": 0.00585,
"Amount": 56.99961222,
"Total": 0.33344773
},
{
"Type": "Sell",
"Price": 0.00585,
"Amount": 0.00007739,
"Total": 4.5e-7
},
{
"Type": "Sell",
"Price": 0.00585,
"Amount": 0.00031039,
"Total": 0.00000181
},
{
"Type": "Buy",
"Price": 8.6e-7,
"Amount": 2070,
"Total": 0.0017802
},
{
"Type": "Buy",
"Price": 0.00187861,
"Amount": 65.81153335,
"Total": 0.1236342
},
{
"Type": "Buy",
"Price": 0.00187858,
"Amount": 15.66747734,
"Total": 0.0294326
},
{
"Type": "Buy",
"Price": 0.00187857,
"Amount": 7.94470487,
"Total": 0.01492468
},
{
"Type": "Buy",
"Price": 0.00187853,
"Amount": 0.78814015,
"Total": 0.00148054
},
{
"Type": "Buy",
"Price": 0.00187852,
"Amount": 0.78814429,
"Total": 0.00148054
},
{
"Type": "Sell",
"Price": 0.00054142,
"Amount": 0.9975,
"Total": 0.00054006
},
{
"Type": "Buy",
"Price": 8.6e-7,
"Amount": 811.9167491,
"Total": 0.00069824
},
{
"Type": "Buy",
"Price": 8.6e-7,
"Amount": 338.0832509,
"Total": 0.00029075
},
{
"Type": "Buy",
"Price": 0.00238719,
"Amount": 72,
"Total": 0.17187768
},
{
"Type": "Buy",
"Price": 0.00236363,
"Amount": 4,
"Total": 0.00945452
},
{
"Type": "Sell",
"Price": 0.00023501,
"Amount": 41.1642077,
"Total": 0.009674
},
{
"Type": "Sell",
"Price": 0.00023501,
"Amount": 2.7697923,
"Total": 0.00065092
},
{
"Type": "Buy",
"Price": 0.00000105,
"Amount": 1270,
"Total": 0.0013335
},
{
"Type": "Buy",
"Price": 0.00281001,
"Amount": 360,
"Total": 1.0116036
},
{
"Type": "Buy",
"Price": 0.00280001,
"Amount": 3.33990832,
"Total": 0.00935177
},
{
"Type": "Sell",
"Price": 0.0038,
"Amount": 208,
"Total": 0.7904
},
{
"Type": "Sell",
"Price": 0.00356245,
"Amount": 1,
"Total": 0.00356245
},
{
"Type": "Sell",
"Price": 0.00370002,
"Amount": 0.02702689,
"Total": 0.0001
},
{
"Type": "Sell",
"Price": 0.00370002,
"Amount": 15.4008193,
"Total": 0.05698333
},
{
"Type": "Sell",
"Price": 0.00370002,
"Amount": 3.09119995,
"Total": 0.0114375
},
{
"Type": "Sell",
"Price": 0.02315202,
"Amount": 6.98549994,
"Total": 0.16172843
},
{
"Type": "Sell",
"Price": 0.02315202,
"Amount": 6e-8,
"Total": 0
},
{
"Type": "Buy",
"Price": 0.00023492,
"Amount": 40,
"Total": 0.0093968
},
{
"Type": "Sell",
"Price": 0.00004456,
"Amount": 40.3006157,
"Total": 0.00179579
},
{
"Type": "Sell",
"Price": 0.00004461,
"Amount": 112.0824927,
"Total": 0.00499999
},
{
"Type": "Sell",
"Price": 0.00004462,
"Amount": 33.61721201,
"Total": 0.00149999
},
{
"Type": "Sell",
"Price": 0.00004463,
"Amount": 33.60967959,
"Total": 0.0015
},
{
"Type": "Buy",
"Price": 0.0002817,
"Amount": 4,
"Total": 0.0011268
},
{
"Type": "Buy",
"Price": 0.00003965,
"Amount": 55.13060038,
"Total": 0.00218592
},
{
"Type": "Buy",
"Price": 0.00003965,
"Amount": 104.8693996,
"Total": 0.00415807
},
{
"Type": "Sell",
"Price": 0.00004129,
"Amount": 149.625,
"Total": 0.00617801
},
{
"Type": "Buy",
"Price": 0.02215591,
"Amount": 3,
"Total": 0.06646773
},
{
"Type": "Buy",
"Price": 0.00004073,
"Amount": 113.3174137,
"Total": 0.00461541
},
{
"Type": "Buy",
"Price": 0.00004072,
"Amount": 36.68258634,
"Total": 0.00149371
},
{
"Type": "Buy",
"Price": 0.0000525,
"Amount": 60,
"Total": 0.00315
},
{
"Type": "Buy",
"Price": 0.01877317,
"Amount": 4,
"Total": 0.07509268
},
{
"Type": "Buy",
"Price": 0.00199501,
"Amount": 43.10755334,
"Total": 0.08599999
},
{
"Type": "Buy",
"Price": 0.00350201,
"Amount": 53.48162609,
"Total": 0.18729318
},
{
"Type": "Buy",
"Price": 0.00350201,
"Amount": 132.1260678,
"Total": 0.46270681
},
{
"Type": "Sell",
"Price": 0.02304826,
"Amount": 17.03647964,
"Total": 0.39266121
},
{
"Type": "Sell",
"Price": 0.02312381,
"Amount": 3.52,
"Total": 0.08139581
},
{
"Type": "Sell",
"Price": 0.02324002,
"Amount": 3.39252036,
"Total": 0.07884224
},
{
"Type": "Buy",
"Price": 0.02459958,
"Amount": 7,
"Total": 0.17219706
},
{
"Type": "Buy",
"Price": 0.01378499,
"Amount": 9,
"Total": 0.12406491
},
{
"Type": "Buy",
"Price": 0.00581178,
"Amount": 1,
"Total": 0.00581178
},
{
"Type": "Buy",
"Price": 0.01498881,
"Amount": 7,
"Total": 0.10492167
},
{
"Type": "Sell",
"Price": 0.00001717,
"Amount": 176.6891735,
"Total": 0.00303375
},
{
"Type": "Sell",
"Price": 0.00001718,
"Amount": 87.31082654,
"Total": 0.00149999
},
{
"Type": "Buy",
"Price": 0.00001464,
"Amount": 182.8870467,
"Total": 0.00267746
},
{
"Type": "Buy",
"Price": 0.00001464,
"Amount": 32.11295335,
"Total": 0.00047013
},
{
"Type": "Buy",
"Price": 0.00596086,
"Amount": 26,
"Total": 0.15498236
},
{
"Type": "Buy",
"Price": 0.000017,
"Amount": 50,
"Total": 0.00085
},
{
"Type": "Buy",
"Price": 0.0005388,
"Amount": 1,
"Total": 0.0005388
},
{
"Type": "Buy",
"Price": 0.00935588,
"Amount": 0.00060288,
"Total": 0.00000564
},
{
"Type": "Buy",
"Price": 0.00935588,
"Amount": 0.99939712,
"Total": 0.00935023
},
{
"Type": "Buy",
"Price": 0.01475001,
"Amount": 1,
"Total": 0.01475001
},
{
"Type": "Buy",
"Price": 0.00555,
"Amount": 21.28693846,
"Total": 0.1181425
},
{
"Type": "Buy",
"Price": 0.00553,
"Amount": 9.26025155,
"Total": 0.05120919
}
]
I'm trying to load it with:
import React, {Component} from 'react';
import Header from './header/header';
import Body from './body/body';
import sdc from './data';
export default class App extends Component {
constructor(props) {
super();
// Set the initial grid in
this.state = {
title: "Singularity is nigh!!!",
sdc: sdc
};
}
render() {
return (
// Add your component markup and other subcomponent references here.
<div>
<Header title={this.state.title} />
<p>{this.state.sdc}</p>
<Body />
</div>
);
}
}
I have got an error saying that:
Uncaught Invariant Violation: Objects are not valid as a React child
(found: object with keys {}). If you meant to render a collection of
children, use an array instead or wrap the object using
createFragment(object) from the React add-ons. Check the render method
of App.
Please advise. I'm trying to do some calculations on the values but first I need to load it and be able to extract values from the object.
Thanks
Edit:
Error:
/scripts/App.js
Module build failed: SyntaxError: Unexpected token (32:30)
30 |
31 | render() {
> 32 | const renderedData = {this._renderData()}
| ^
33 |
34 |
35 | return (
BabelLoaderError: SyntaxError: Unexpected token (32:30)
30 |
31 | render() {
> 32 | const renderedData = {this._renderData()}
| ^
33 |
34 |
35 | return (
EDIT 2:
import React, {Component} from 'react';
import Header from './header/header';
import Body from './body/body';
import sdc from './data';
export default class App extends Component {
constructor(props) {
super();
// Set the initial grid in
this.state = {
title: "Singularity is nigh!!!",
sdc: sdc
};
}
_renderData(){
const data = this.state.sdc
return Object.keys(data).map(function(key,index){
return ( <div key={datum.id}>
<p>{datum.Type}</p>
<p>{datum.Price}</p>
//other properties
</div> )
})
}
render() {
const renderedData = this._renderData()
return (
// Add your component markup and other subcomponent references here.
<div>
<p>{renderedData}</p>
</div>
);
}
}
Ideally you should not render objects(or array) this way. The correct way is to iterate over the array(or object) and then printing the data. Somewhat like this:-
_renderData(){
const data = this.state.sdc
return Object.keys(data).map(function(key,index){
const datum = data[key]
return ( <div key={datum.id}>
<p>{datum.Type}</p>
<p>{datum.Price}</p>
//other properties
</div> )
})
}
render(){
const renderedData = this._renderData()
return (
// Add your component markup and other subcomponent references here.
<div>
<Header title={this.state.title} />
<p>{renderedData}</p>
<Body />
</div>
);
}
React wants to render a component. You are passing a (presumably) JSON object.
If you wanted to see the JSON rendered you could modify your output line to
<p>{JSON.stringify(this.state.sdc)}</p>
You data.js is wrong:
const sdc = [
You need to have export statement, so this should be:
export default [
Otherwise, importing sdc will just give you an empty document.

in2csv fail on JSON

I have a small JSON file which fails to convert a data value properly. The value in question is the "id" field and the conversion produces 2016-05-06. I have a much larger file (same format) and it works properly. Any help?
{
"results": [
{
"seq": "10457-g1AAAAPreJy90lFqAjEQBuCgFj2B4EOpUgRfXNyscWef9CbtTMZFZF3Brs96E3uT9ib1IMIaE2XpmynUlwkE8n_8TDIhRGtRZzFg0uvNfMakAloNGbPhR4E544ZloLP1ljEvgnxeZOZFDQW9lGW5XNRJiKfnlblrYiRZqtQj6rcr73CpayZNK3pg6bGOmZE80vwr0-xCv1X0q6XViDGJ_t46vId-v9C7iu5YegIEmIw90vxb5w0zxd4cRj9c-Z7lSUEEIP-1ueM_Hf_l-MbJ8iGmxDE8oP2343-u7fvuy6WaRqQf0P7o-Nvu25ZPATRA6JG4PAMPEEFw",
"id": "20160506175330-3168-01",
"changes": [
{
"rev": "1-8bda66017d962508e51ac5061557635b"
}
],
"doc": {
"_id": "20160506175330-3168-01",
"_rev": "1-8bda66017d962508e51ac5061557635b",
"year": "2016",
"month": "05",
"day": "06",
"hour": "17",
"minute": "53",
"second": "30",
"imagebox": "18x94+428+180",
"alchemy": {
"text": "person",
"score": "0.845535"
},
"visual": {
"image": "20160506175330-3168-01.jpg",
"scores": [
{
"classifier_id": "Mixed_Color",
"name": "Mixed_Color",
"score": 0.964822
},
{
"classifier_id": "Stove",
"name": "Stove",
"score": 0.923713
},
{
"classifier_id": "Archery",
"name": "Archery",
"score": 0.836994
},
{
"classifier_id": "Dish_Washer",
"name": "Dish_Washer",
"score": 0.835787
},
{
"classifier_id": "Barber_Shop",
"name": "Barber_Shop",
"score": 0.825716
},
{
"classifier_id": "Full_Body",
"name": "Full_Body",
"score": 0.824954
},
{
"classifier_id": "Musical_Instrument",
"name": "Musical_Instrument",
"score": 0.817304
},
{
"classifier_id": "Beauty_Salon",
"name": "Beauty_Salon",
"score": 0.808518
},
{
"classifier_id": "Clothing_Store",
"name": "Clothing_Store",
"score": 0.784035
},
{
"classifier_id": "Distillery",
"name": "Distillery",
"score": 0.67477
},
{
"classifier_id": "Sweet_Treat",
"name": "Sweet_Treat",
"score": 0.588916
},
{
"classifier_id": "Beer",
"name": "Beer",
"score": 0.538915
},
{
"classifier_id": "Store",
"name": "Store",
"score": 0.536244
},
{
"classifier_id": "Yellow",
"name": "Yellow",
"score": 0.526932
}
]
}
}
}
],
"last_seq": "10457-g1AAAAPreJy90lFqAjEQBuCgFj2B4EOpUgRfXNyscWef9CbtTMZFZF3Brs96E3uT9ib1IMIaE2XpmynUlwkE8n_8TDIhRGtRZzFg0uvNfMakAloNGbPhR4E544ZloLP1ljEvgnxeZOZFDQW9lGW5XNRJiKfnlblrYiRZqtQj6rcr73CpayZNK3pg6bGOmZE80vwr0-xCv1X0q6XViDGJ_t46vId-v9C7iu5YegIEmIw90vxb5w0zxd4cRj9c-Z7lSUEEIP-1ueM_Hf_l-MbJ8iGmxDE8oP2343-u7fvuy6WaRqQf0P7o-Nvu25ZPATRA6JG4PAMPEEFw",
"pending": 0
}
I needed to use --no-inference.