Converting JSON data to model class Flutter - json

I want to convert JSON data to model class, I used this https://javiercbk.github.io/json_to_dart/ but I am not getting what I want, can you please assist.
My JSON data
[
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 5,
"Category": "Valuation",
"Description": "AdjustedValues",
"Value": [],
"ServiceResponsePropertyId": 474,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 1,
"Category": "General",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 475,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "CarId",
"Value": 120354,
"ServiceResponsePropertyId": 100,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Year",
"Value": 2017,
"ServiceResponsePropertyId": 103,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 6
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Full Model Description",
"Value": "2017 AUDI A3 Sedan 1.0T FSI S tronic [2016-2017]",
"ServiceResponsePropertyId": 104,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Model",
"Value": "A3 Sedan 1.0T FSI S tronic [2016-2017]",
"ServiceResponsePropertyId": 105,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 5
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "ImageUrl",
"Value": "https://cdn.lightstoneauto.co.za/PHOTOS/AUDI/120354_1_Z7.jpg",
"ServiceResponsePropertyId": 107,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Make",
"Value": "AUDI",
"ServiceResponsePropertyId": 110,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 3
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "Type",
"Value": "AUDI A3 Sedan",
"ServiceResponsePropertyId": 111,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 4
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 6,
"CategoryId": 1,
"Category": "General",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 125,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 126,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13818024,
"SortOrder": 9999
},
{
"CarId": 0,
"SpecCategory": "General",
"Id": -1,
"SourceId": -1,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "Body shape",
"Value": "Sedan",
"ServiceResponsePropertyId": 320,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 9999
},
{
"CarId": 0,
"SpecCategory": "General",
"Id": -6,
"SourceId": -6,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "Drive type",
"Value": "4x2",
"ServiceResponsePropertyId": 154,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 9999
},
{
"CarId": 0,
"SpecCategory": "General",
"Id": -7,
"SourceId": -7,
"ServiceId": 7,
"CategoryId": 1,
"Category": "General",
"Description": "Fuel type",
"Value": "Petrol",
"ServiceResponsePropertyId": 153,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 9999
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "LastFiveSales",
"Value": [
{
"SaleId": 698229,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-06-09T15:30:38Z",
"SalePrice": 299900.0,
"MunicipalityName": "CITY OF TSHWANE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 695530,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-05-30T13:24:17Z",
"SalePrice": 289995.0,
"MunicipalityName": "CITY OF TSHWANE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 685020,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-04-14T12:27:37Z",
"SalePrice": 366948.0,
"MunicipalityName": "EMFULENI",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 683843,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-04-11T15:00:38Z",
"SalePrice": 315500.0,
"MunicipalityName": "UMHLATHUZE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"SaleId": 652718,
"CarId": 120354,
"SaleYear": 2017,
"SaleDateTime": "2022-04-01T11:53:45Z",
"SalePrice": 339900.0,
"MunicipalityName": "CITY OF TSHWANE",
"Id": 0,
"SourceId": 0,
"ServiceId": 0,
"CategoryId": 0,
"Category": null,
"Description": null,
"Value": null,
"ServiceResponsePropertyId": 0,
"MappingId": 1,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
}
],
"ServiceResponsePropertyId": 481,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 0
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "ServiceStatus",
"Value": {
"StatusCode": 1,
"StatusDescription": "Ok",
"StatusDetail": "",
"RestServiceStatus": null,
"ServiceResource": null
},
"ServiceResponsePropertyId": 482,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 13818024,
"SortOrder": 0
},
{
"EstimateType": "Auction",
"CarId": 0,
"Id": 1,
"SourceId": 1,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Auction Estimate",
"Value": 189400.0,
"ServiceResponsePropertyId": 494,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"EstimateType": "Cost",
"CarId": 0,
"Id": 2,
"SourceId": 2,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Cost Estimate",
"Value": 238300.0,
"ServiceResponsePropertyId": 495,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"EstimateType": "Cost",
"CarId": 0,
"Id": 3,
"SourceId": 3,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Cost Estimate High",
"Value": 259800.0,
"ServiceResponsePropertyId": 496,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 3
},
{
"EstimateType": "Cost",
"CarId": 0,
"Id": 4,
"SourceId": 4,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Cost Estimate Low",
"Value": 218700.0,
"ServiceResponsePropertyId": 497,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 2
},
{
"EstimateType": "Retail",
"CarId": 0,
"Id": 5,
"SourceId": 5,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Retail Estimate",
"Value": 300800.0,
"ServiceResponsePropertyId": 498,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"EstimateType": "Retail",
"CarId": 0,
"Id": 6,
"SourceId": 6,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Retail Estimate High",
"Value": 327900.0,
"ServiceResponsePropertyId": 499,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 3
},
{
"EstimateType": "Retail",
"CarId": 0,
"Id": 7,
"SourceId": 7,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Retail Estimate Low",
"Value": 276000.0,
"ServiceResponsePropertyId": 500,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 2
},
{
"EstimateType": "Trade",
"CarId": 0,
"Id": 8,
"SourceId": 8,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Trade Estimate",
"Value": 261300.0,
"ServiceResponsePropertyId": 501,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 1
},
{
"EstimateType": "Trade",
"CarId": 0,
"Id": 9,
"SourceId": 9,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Trade Estimate High",
"Value": 284900.0,
"ServiceResponsePropertyId": 502,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 3
},
{
"EstimateType": "Trade",
"CarId": 0,
"Id": 10,
"SourceId": 10,
"ServiceId": 12,
"CategoryId": 5,
"Category": "Valuation",
"Description": "Trade Estimate Low",
"Value": 239800.0,
"ServiceResponsePropertyId": 503,
"MappingId": 0,
"IsVisible": true,
"PackageRequestId": 13818024,
"SortOrder": 2
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 7,
"Category": "Report",
"Description": "ReportUrl",
"Value": "https://pdf.lightstoneauto.co.za/Index.aspx?sourceurl=https://cdn.lightstoneauto.co.za/REPORTS/LIVE/ba22673b-0f05-4ae9-b212-0369a7c793ad.html",
"ServiceResponsePropertyId": 0,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
},
{
"Id": 0,
"SourceId": 0,
"ServiceId": 11,
"CategoryId": 7,
"Category": "Report",
"Description": "HtmlUrl",
"Value": "https://cdn.lightstoneauto.co.za/REPORTS/LIVE/ba22673b-0f05-4ae9-b212-0369a7c793ad.html",
"ServiceResponsePropertyId": 0,
"MappingId": 0,
"IsVisible": false,
"PackageRequestId": 0,
"SortOrder": 0
}
]
I want to show only type "Value" on the UI, so can anyone assist on how can I create the model class with this json data then show the "Value" on a list or text so can anyone please help on how do I go about this?? I have stuck for a while now. Your help will be appreciated, thanks in advance.

class DartClass {
int? id;
int? sourceId;
int? serviceId;
int? categoryId;
String? category;
String? description;
dynamic value;
int? serviceResponsePropertyId;
int? mappingId;
bool? isVisible;
int? packageRequestId;
int? sortOrder;
DartClass(
{this.id,
this.sourceId,
this.serviceId,
this.categoryId,
this.category,
this.description,
this.value,
this.serviceResponsePropertyId,
this.mappingId,
this.isVisible,
this.packageRequestId,
this.sortOrder});
DartClass.fromJson(Map<String, dynamic> json) {
id = json['Id'];
sourceId = json['SourceId'];
serviceId = json['ServiceId'];
categoryId = json['CategoryId'];
category = json['Category'];
description = json['Description'];
value = json['Value'];
serviceResponsePropertyId = json['ServiceResponsePropertyId'];
mappingId = json['MappingId'];
isVisible = json['IsVisible'];
packageRequestId = json['PackageRequestId'];
sortOrder = json['SortOrder'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = {};
data['Id'] = id;
data['SourceId'] = sourceId;
data['ServiceId'] = serviceId;
data['CategoryId'] = categoryId;
data['Category'] = category;
data['Description'] = description;
data['Value'] = value;
data['ServiceResponsePropertyId'] = serviceResponsePropertyId;
data['MappingId'] = mappingId;
data['IsVisible'] = isVisible;
data['PackageRequestId'] = packageRequestId;
data['SortOrder'] = sortOrder;
return data;
}
}

Related

How do i transform a nested json to Jolt in Apache NIFI

I have an API with the below JSON format:
{
"message": true,
"result": [
{
"category": "Device",
"total_count": 288,
"total_price": 1769005231,
"brands": [
{
"brand": "DD",
"total_count": 127,
"total_price": 815344231,
"models": [
{
"model": "A01 Core",
"total_count": 0,
"total_price": 31231,
"items": [
{
"systemCode": "2000010010001001001001001",
"sku": "TEST DD A01 Core (1GB 16GB 4G) VV",
"model": "A01 Core",
"seller": "DSA",
"color": "Black",
"guaranty": "AORD",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 31231
},
{
"systemCode": "2000010010001001001001001",
"sku": "TEST DD A01 Core (1GB 16GB 4G) VV",
"model": "A01 Core",
"seller": "DSA",
"color": "Black",
"guaranty": "AORD",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 1000000
}
]
},
{
"model": "A13",
"total_count": 12,
"total_price": 61237000,
"items": [
{
"systemCode": "2000010010007001001001002",
"sku": "TEST DD A13 (4GB 64GB 4G) VV",
"model": "A13",
"seller": "DSA",
"color": "Black",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 4249000
}
]
},
{
"model": "A22 5G",
"total_count": 0,
"total_price": 5239000,
"items": [
{
"systemCode": "2000010010010004001016002",
"sku": "TEST DD A22 5G (4GB 128GB 5G) II",
"model": "A22 5G",
"seller": "DSA",
"color": "White",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 5147010,
"price": 5239000
},
{
"systemCode": "2000010010010007001003002",
"sku": "TEST DD A22 5G (4GB 128GB 5G) RX | DSA | SSS [Gray]",
"model": "A22 5G",
"seller": "DSA",
"color": "Gray",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 5398044,
"price": 5299000
},
{
"systemCode": "2000010010010007001016002",
"sku": "TEST DD A22 5G (4GB 128GB 5G) RX | DSA | SSS [White]",
"model": "A22 5G",
"seller": "DSA",
"color": "White",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 5239000
}
]
},
{
"model": "A52",
"total_count": 0,
"total_price": 8299000,
"items": [
{
"systemCode": "2000010010014002001001002",
"sku": "TEST DD A52 (8GB 128GB 4G) II",
"model": "A52",
"seller": "DSA",
"color": "Black",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 8299000
},
{
"systemCode": "2000010010014004001005002",
"sku": "TEST DD A52 (8GB 256GB 4G) II",
"model": "A52",
"seller": "DSA",
"color": "Blue",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 9099000
}
]
},
{
"model": "A52s",
"total_count": 12,
"total_price": 152487000,
"items": [
{
"systemCode": "2000010010015002001008001",
"sku": "TEST DD A52s (8GB 128GB 5G) II",
"model": "A52s",
"seller": "DSA",
"color": "Mint",
"guaranty": "AORD",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 9701010,
"price": 10159000
},
{
"systemCode": "2000010010015004001001001",
"sku": "TEST DD A52s (8GB 256GB 5G) II",
"model": "A52s",
"seller": "DSA",
"color": "Black",
"guaranty": "AORD",
"stockId": "903",
"quantity": 7,
"reserve": 0,
"salable": 7,
"dailySales": 0,
"balancedAvg": 11681010,
"price": 11919000
},
{
"systemCode": "2000010010015004001016001",
"sku": "TEST DD A52s (8GB 256GB 5G) II",
"model": "A52s",
"seller": "DSA",
"color": "White",
"guaranty": "AORD",
"stockId": "903",
"quantity": 5,
"reserve": 0,
"salable": 5,
"dailySales": 0,
"balancedAvg": 11483010,
"price": 11779000
},
{
"systemCode": "2000010010015004001016002",
"sku": "TEST DD A52s (8GB 256GB 5G) II",
"model": "A52s",
"seller": "DSA",
"color": "White",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 11599000
}
]
},
{
"model": "A53",
"total_count": 0,
"total_price": 11379000,
"items": [
{
"systemCode": "2000010010016004001001002",
"sku": "TEST DD A53 (8GB 256GB 5G) II",
"model": "A53",
"seller": "DSA",
"color": "Black",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 11797000,
"price": 11379000
},
{
"systemCode": "2000010010016004001005002",
"sku": "TEST DD A53 (8GB 256GB 5G) II",
"model": "A53",
"seller": "DSA",
"color": "Blue",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 11855425,
"price": 11349000
}
]
},
{
"model": "A03",
"total_count": 0,
"total_price": 3099000,
"items": [
{
"systemCode": "2000010010003007001001001",
"sku": "TEST DD A03 (3GB 32GB 4G) RX",
"model": "A03",
"seller": "DSA",
"color": "Black",
"guaranty": "AORD",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 3099000
}
]
}
]
},
{
"brand": "red",
"total_count": 28,
"total_price": 230893000,
"models": [
{
"model": "Ride 3 Pro 5G",
"total_count": 0,
"total_price": 5189000,
"items": [
{
"systemCode": "2000010050005003001030002",
"sku": "TEST Ride 3 Pro 5G (6GB 128GB 5G) Global",
"model": "Ride 3 Pro 5G",
"seller": "DSA",
"color": "Power Black",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 5088000,
"price": 5189000
}
]
},
{
"model": "Ride 4 Pro ",
"total_count": 0,
"total_price": 6769000,
"items": [
{
"systemCode": "2000010050006002001030002",
"sku": "TEST Ride 4 Pro (8GB 256GB 4G) Global",
"model": "Ride 4 Pro ",
"seller": "DSA",
"color": "Power Black",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 6769000
},
{
"systemCode": "2000010050006002001032002",
"sku": "TEST Ride 4 Pro (8GB 256GB 4G) Global",
"model": "Ride 4 Pro ",
"seller": "DSA",
"color": "Cool Blue",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 6759000
}
]
},
{
"model": "Ride 4 Pro 5G",
"total_count": 0,
"total_price": 5759000,
"items": [
{
"systemCode": "2000010050007001001030002",
"sku": "TEST Ride 4 Pro 5G (6GB 128GB 5G) Global",
"model": "Ride 4 Pro 5G",
"seller": "DSA",
"color": "Power Black",
"guaranty": "SSS",
"stockId": "903",
"quantity": 0,
"reserve": 0,
"salable": 0,
"dailySales": 0,
"balancedAvg": 0,
"price": 5759000
}
]
},
{
"model": "red F3",
"total_count": 2,
"total_price": 10875000,
"items": [
{
"systemCode": "2000010050010002001102002",
"sku": "TEST red F3 (8GB 256GB 5G) Global | DSA | SSS [Arctic White]",
"model": "red F3",
"seller": "DSA",
"color": "Arctic White",
"guaranty": "SSS",
"stockId": "903",
"quantity": 2,
"reserve": 0,
"salable": 2,
"dailySales": 0,
"balancedAvg": 10450000,
"price": 10875000
}
]
},
{
"model": "red C31",
"total_count": 1,
"total_price": 3359000,
"items": [
{
"systemCode": "2000010050001004001043002",
"sku": "TEST red C31 (4GB 64GB 4G) II | DSA | SSS [Shadow Gray]",
"model": "red C31",
"seller": "DSA",
"color": "Shadow Gray",
"guaranty": "SSS",
"stockId": "903",
"quantity": 1,
"reserve": 0,
"salable": 1,
"dailySales": 0,
"balancedAvg": 3299000,
"price": 3359000
}
]
}
]
}
]
}
]
}
I want to transform this JSON to JOLT and import the result to a Mysql Table. The table has the below columns:
Brand ,Model ,total_count_model ,systemcode ,sku ,seller
How can i convert the JSON file to a Jolttransformjson?
I also use Jolt Transformation DSL and tried some JOLT specification.
Thank you
You can walk through indexes of the innermost array(namely items) within a shift transformation spec such as
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"brands": {
"*": {
"models": {
"*": {
"items": {
"*": {
"#(4,brand)": "[&5].[&3].&1.brand",
"#(2,model)": "[&5].[&3].&1.model",
"#(2,total_count)": "[&5].[&3].&1.total_count",
"model": "[&5].[&3].&1.items_model",
"systemCode": "[&5].[&3].&1.systemCode",
"sku": "[&5].[&3].&1.sku",
"seller": "[&5].[&3].&1.seller"
}
}
}
}
}
}
}
}
}
},
{
// get rid of the object labels
"operation": "shift",
"spec": {
"*": {
"*": {
"*": ""
}
}
}
}
]

Vegalite: pie chart not aggregating together

I have a json date values that I'm adding to the vega-lite for visualization in pie chart. The legends seem to render properly (there's 2 distinct legends for 2020 q3 and 2020 q4). But the pie chart itself doesn't seem to aggregate together. How would I make sure that all the 2020Q4 are grouping together? How do I fix my spec??
pie chart with no aggregation for same data
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 880,
"height": 376,
"config": {
"range": {
"category": {
"scheme": "tableau20"
}
},
"legend": {
"labelColor": "#333",
"labelFontSize": 11,
"symbolSize": 30,
"symbolType": "circle",
"symbolStrokeWidth": 0,
"titleColor": "#333",
"titleFontSize": 14,
"titlePadding": 10,
"titleFontWeight": 500
},
"autosize": {
"type": "fit",
"contains": "padding"
},
"font": "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"axisLeft": {
"labelFontSize": 14,
"labelColor": "#333",
"labelLimit": 180,
"titleFontSize": 16,
"titleLimit": 180
},
"style": {
"label": {
"align": "left",
"baseline": "middle",
"dx": 4
},
"cell": {
"stroke": "transparent"
}
}
},
"layer": [
{
"mark": {
"type": "arc",
"innerRadius": {
"expr": "min(width,height)/5"
},
"outerRadius": {
"expr": "min(width,height)/4"
},
"tooltip": true,
"padAngle": 0.01
},
"params": [
{
"name": "highlight",
"select": {
"type": "point",
"on": "mouseover"
}
},
{
"name": "select",
"select": "point"
}
]
},
{
"mark": {
"type": "text",
"radius": {
"expr": "min(width,height)/4+min(width,height)/5/2"
},
"stroke": "#666666",
"limit": {
"expr": "min(width,height)/5"
}
},
"encoding": {
"text": {
"field": "color",
"title": "Due date",
"type": "nominal",
"timeUnit": "yearquarter"
}
}
}
],
"encoding": {
"color": {
"field": "color",
"title": "Due date",
"type": "nominal",
"timeUnit": "yearquarter"
},
"theta": {
"field": "thetaAggregated",
"type": "quantitative",
"title": "Values",
"stack": true
},
"fillOpacity": {
"condition": [
{
"param": "select",
"value": 1
}
],
"value": 0.3
}
},
"transform": [
{
"calculate": "datetime(datum.color.year, datum.color.month, datum.color.date)",
"as": "color"
},
{
"joinaggregate": [
{
"op": "count",
"field": "theta",
"as": "thetaAggregated"
}
],
"groupby": [
"color"
]
}
],
"data": {
"values": [
{
"color": {
"year": 2020,
"month": 9,
"date": 30,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "rec79Wjae6P45XNpl"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 20,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recrQaNcIH4wueWrT"
},
{
"color": {
"year": 2020,
"month": 8,
"date": 29,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recwVzB5CNu0E6x9J"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 25,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recp8FrOTOgSqQlxV"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 5,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recpgd5QYGyHPz6oC"
},
{
"color": {
"year": 2020,
"month": 10,
"date": 7,
"hours": 16,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recerFXuq7ply21Ba"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 18,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recNfz0B2qasVXfwS"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 12,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recriiVtRVuueAwTP"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 19,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recbGumPg7L28cUrh"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 26,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recrhgU6BXOBYY8F4"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 31,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recJzAP0NPlzck0aa"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 32,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "rec2spYZGJTOnq32F"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 17,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recldmzqvJhcZ9oqy"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 25,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recegvuNEeNoSyyMT"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 4,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recDwkAeTWQ9KzDXS"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 9,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recKTwDYDpXsKAiAC"
}
]
}
}
Instead of joinaggregate, you can use aggregate transform as it will help you to generate new data set which you can utilize for the values pie chart. Simply convert the color values using calculate and expressions and then perform aggregation.
Below is the code snippet or refer editor:
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"width": 880,
"height": 376,
"config": {
"range": {"category": {"scheme": "tableau20"}},
"legend": {
"labelColor": "#333",
"labelFontSize": 11,
"symbolSize": 30,
"symbolType": "circle",
"symbolStrokeWidth": 0,
"titleColor": "#333",
"titleFontSize": 14,
"titlePadding": 10,
"titleFontWeight": 500
},
"autosize": {"type": "fit", "contains": "padding"},
"font": "-apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\"",
"axisLeft": {
"labelFontSize": 14,
"labelColor": "#333",
"labelLimit": 180,
"titleFontSize": 16,
"titleLimit": 180
},
"style": {
"label": {"align": "left", "baseline": "middle", "dx": 4},
"cell": {"stroke": "transparent"}
}
},
"layer": [
{
"mark": {
"type": "arc",
"innerRadius": {"expr": "min(width,height)/5"},
"outerRadius": {"expr": "min(width,height)/4"},
"tooltip": true,
"padAngle": 0.01
},
"params": [
{"name": "highlight", "select": {"type": "point", "on": "mouseover"}},
{"name": "select", "select": "point"}
]
},
{
"mark": {
"type": "text",
"stroke": "#666666",
"radius": {"expr": "min(width,height)/4+min(width,height)/5/2"},
"limit": {"expr": "min(width,height)/5"}
},
"encoding": {
"text": {"field": "quarterTime", "title": "Due date", "type": "nominal"}
}
}
],
"encoding": {
"color": {"field": "quarterTime", "title": "Due date", "type": "nominal"},
"theta": {
"field": "thetaAggregated",
"type": "quantitative",
"title": "Values",
"stack": true
},
"fillOpacity": {
"condition": [{"param": "select", "value": 1}],
"value": 0.3
}
},
"transform": [
{
"calculate": "datetime(datum.color.year, datum.color.month, datum.color.date)",
"as": "color"
},
{"calculate": "timeFormat(datum.color,'%Y Q%q')", "as": "quarterTime"},
{
"aggregate": [{"op": "count", "field": "theta", "as": "thetaAggregated"}],
"groupby": ["quarterTime"]
}
],
"data": {
"values": [
{
"color": {
"year": 2020,
"month": 9,
"date": 30,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "rec79Wjae6P45XNpl"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 20,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recrQaNcIH4wueWrT"
},
{
"color": {
"year": 2020,
"month": 8,
"date": 29,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recwVzB5CNu0E6x9J"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 25,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recp8FrOTOgSqQlxV"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 5,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recpgd5QYGyHPz6oC"
},
{
"color": {
"year": 2020,
"month": 10,
"date": 7,
"hours": 16,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recerFXuq7ply21Ba"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 18,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recNfz0B2qasVXfwS"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 12,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recriiVtRVuueAwTP"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 19,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recbGumPg7L28cUrh"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 26,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recrhgU6BXOBYY8F4"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 31,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recJzAP0NPlzck0aa"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 32,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "rec2spYZGJTOnq32F"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 17,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recldmzqvJhcZ9oqy"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 25,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recegvuNEeNoSyyMT"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 4,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recDwkAeTWQ9KzDXS"
},
{
"color": {
"year": 2020,
"month": 9,
"date": 9,
"hours": 17,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
},
"theta": "recKTwDYDpXsKAiAC"
}
]
}
}

Unexpected end of JSON input when using fs.watch() and require() NodeJS

When checking for a new file inside my ./Assetto1/results folder (.json file) the code should read the new file (result = require("[...]")) and log it into console. But I'm always getting the same error. Even trying for 8 hours now. The same thing happens, when using fs.readFile() instead of require(). I even tried an npm module called "decache" so that I could somehow "derequire" the file. My idea was that nodejs then expects the end of the JSON file. But nothing of this helps, as well.
Take a look at my code i wrote:
var fs = require("fs");
fs.watch('./Assetto1/results/', (eventType, filename) => {
console.log("EventType:"+eventType);
if (eventType == "rename") {
console.log("Debug: Rename");
console.log("./Assetto1/results/"+filename);
result = require("./Assetto1/results/"+filename);
console.log(result);
}
})
Console Output looks like this:
SyntaxError: /home/Assetto1/results/2018_9_8_9_0_RACE.json: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Object.Module._extensions..json (internal/modules/cjs/loader.js:708:27)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:20:18)
at FSWatcher.fs.watch (/home/main.js:59:12)
at FSWatcher.emit (events.js:182:13)
at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:130:12)
Content of the JSON file (AssettoCorsa Race-Results):
{
"TrackName": "spa",
"TrackConfig": "",
"Type": "RACE",
"DurationSecs": 0,
"RaceLaps": 5,
"Cars": [
{
"CarId": 0,
"Driver": {
"Name": "NoaH",
"Team": "",
"Nation": "DEU",
"Guid": "76561198190801825",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Black_Falcon_SB_Mobel_Boss_10",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 1,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Black_Falcon_Porta_9",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 2,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Kunos_zp_115",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 3,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Kunos_zp_116",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 4,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Black_Falcon_Dubai_24H_2",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 5,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Black_Falcon_SB_Mobel_Boss_10",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 6,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Black_Falcon_Porta_9",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 7,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Kunos_zp_115",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 8,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Kunos_zp_116",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 9,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "mercedes_sls_gt3",
"Skin": "Black_Falcon_Dubai_24H_2",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 10,
"Driver": {
"Name": "Ian Loncar",
"Team": "",
"Nation": "HRV",
"Guid": "76561198273369988",
"GuidsList": [
""
]
},
"Model": "ks_nissan_gtr",
"Skin": "solid_red",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 11,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_nissan_gtr",
"Skin": "jet_black",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 12,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_nissan_gtr",
"Skin": "0_pearl_white",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 13,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_nissan_gtr",
"Skin": "super_silver",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 14,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_nissan_gtr",
"Skin": "jet_black",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 15,
"Driver": {
"Name": "F. Riestra.ESP.",
"Team": "",
"Nation": "",
"Guid": "76561198130349639",
"GuidsList": [
""
]
},
"Model": "ks_audi_r8_plus",
"Skin": "10_sepang_blue_pearl",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 16,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_audi_r8_plus",
"Skin": "11_suzuka_gray_metallic_t",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 17,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_audi_r8_plus",
"Skin": "09_samoa_orange_metallic_t",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 18,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_audi_r8_plus",
"Skin": "Brilliant_Red",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 19,
"Driver": {
"Name": "sale7almanna3i",
"Team": "",
"Nation": "QAT",
"Guid": "76561198139068257",
"GuidsList": [
""
]
},
"Model": "ks_lamborghini_huracan_performante",
"Skin": "blu_cepheus",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 20,
"Driver": {
"Name": "raafaal1661",
"Team": "",
"Nation": "",
"Guid": "76561198857669454",
"GuidsList": [
""
]
},
"Model": "ks_lamborghini_huracan_performante",
"Skin": "giallo_horus",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 21,
"Driver": {
"Name": "alexpavillanueva",
"Team": "",
"Nation": "ESP",
"Guid": "76561198834760853",
"GuidsList": [
""
]
},
"Model": "ks_lamborghini_huracan_performante",
"Skin": "blu_nethuns",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 22,
"Driver": {
"Name": "NoaH",
"Team": "",
"Nation": "DEU",
"Guid": "76561198190801825",
"GuidsList": [
""
]
},
"Model": "ks_lamborghini_huracan_performante",
"Skin": "00_arancio_anthaeus",
"BallastKG": 0,
"Restrictor": 0
},
{
"CarId": 23,
"Driver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": [
""
]
},
"Model": "ks_lamborghini_huracan_performante",
"Skin": "rosso_efesto",
"BallastKG": 0,
"Restrictor": 0
}
],
"Result": [
{
"DriverName": "NoaH",
"DriverGuid": "76561198190801825",
"CarId": 22,
"CarModel": "ks_lamborghini_huracan_performante",
"BestLap": 174182,
"TotalTime": 891017,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "NoaH",
"DriverGuid": "76561198190801825",
"CarId": 0,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 2,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 3,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 4,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 5,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 6,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 7,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 8,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 9,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "Ian Loncar",
"DriverGuid": "76561198273369988",
"CarId": 10,
"CarModel": "ks_nissan_gtr",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 11,
"CarModel": "ks_nissan_gtr",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 12,
"CarModel": "ks_nissan_gtr",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 13,
"CarModel": "ks_nissan_gtr",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 14,
"CarModel": "ks_nissan_gtr",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "F. Riestra.ESP.",
"DriverGuid": "76561198130349639",
"CarId": 15,
"CarModel": "ks_audi_r8_plus",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 16,
"CarModel": "ks_audi_r8_plus",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 17,
"CarModel": "ks_audi_r8_plus",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 18,
"CarModel": "ks_audi_r8_plus",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "sale7almanna3i",
"DriverGuid": "76561198139068257",
"CarId": 19,
"CarModel": "ks_lamborghini_huracan_performante",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "raafaal1661",
"DriverGuid": "76561198857669454",
"CarId": 20,
"CarModel": "ks_lamborghini_huracan_performante",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "alexpavillanueva",
"DriverGuid": "76561198834760853",
"CarId": 21,
"CarModel": "ks_lamborghini_huracan_performante",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 1,
"CarModel": "mercedes_sls_gt3",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
},
{
"DriverName": "",
"DriverGuid": "",
"CarId": 23,
"CarModel": "ks_lamborghini_huracan_performante",
"BestLap": 999999999,
"TotalTime": 0,
"BallastKG": 0,
"Restrictor": 0
}
],
"Laps": [
{
"DriverName": "NoaH",
"DriverGuid": "76561198190801825",
"CarId": 22,
"CarModel": "ks_lamborghini_huracan_performante",
"Timestamp": 35470691,
"LapTime": 180196,
"Sectors": [
50515,
82440,
47241
],
"Cuts": 0,
"BallastKG": 0,
"Tyre": "HR",
"Restrictor": 0
},
{
"DriverName": "NoaH",
"DriverGuid": "76561198190801825",
"CarId": 22,
"CarModel": "ks_lamborghini_huracan_performante",
"Timestamp": 35645934,
"LapTime": 175240,
"Sectors": [
48331,
82125,
44784
],
"Cuts": 0,
"BallastKG": 0,
"Tyre": "HR",
"Restrictor": 0
},
{
"DriverName": "NoaH",
"DriverGuid": "76561198190801825",
"CarId": 22,
"CarModel": "ks_lamborghini_huracan_performante",
"Timestamp": 35824671,
"LapTime": 178746,
"Sectors": [
46162,
85482,
47102
],
"Cuts": 0,
"BallastKG": 0,
"Tyre": "HR",
"Restrictor": 0
},
{
"DriverName": "NoaH",
"DriverGuid": "76561198190801825",
"CarId": 22,
"CarModel": "ks_lamborghini_huracan_performante",
"Timestamp": 36007357,
"LapTime": 182686,
"Sectors": [
46340,
85492,
50854
],
"Cuts": 0,
"BallastKG": 0,
"Tyre": "HR",
"Restrictor": 0
},
{
"DriverName": "NoaH",
"DriverGuid": "76561198190801825",
"CarId": 22,
"CarModel": "ks_lamborghini_huracan_performante",
"Timestamp": 36181518,
"LapTime": 174182,
"Sectors": [
46693,
81995,
45494
],
"Cuts": 0,
"BallastKG": 0,
"Tyre": "HR",
"Restrictor": 0
}
],
"Events": [
{
"Type": "COLLISION_WITH_ENV",
"CarId": 22,
"Driver": {
"Name": "NoaH",
"Team": "",
"Nation": "DEU",
"Guid": "76561198190801825",
"GuidsList": [
""
]
},
"OtherCarId": -1,
"OtherDriver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": null
},
"ImpactSpeed": 12.305487,
"WorldPosition": {
"X": 415.25763,
"Y": 38.005207,
"Z": 847.0971
},
"RelPosition": {
"X": -0.96855915,
"Y": 0.31426933,
"Z": -1.4876876
}
},
{
"Type": "COLLISION_WITH_ENV",
"CarId": 22,
"Driver": {
"Name": "NoaH",
"Team": "",
"Nation": "DEU",
"Guid": "76561198190801825",
"GuidsList": [
""
]
},
"OtherCarId": -1,
"OtherDriver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": null
},
"ImpactSpeed": 69.01873,
"WorldPosition": {
"X": -449.24142,
"Y": 30.581987,
"Z": -1006.0361
},
"RelPosition": {
"X": 0.68840855,
"Y": -0.285217,
"Z": 2.4184985
}
},
{
"Type": "COLLISION_WITH_ENV",
"CarId": 22,
"Driver": {
"Name": "NoaH",
"Team": "",
"Nation": "DEU",
"Guid": "76561198190801825",
"GuidsList": [
""
]
},
"OtherCarId": -1,
"OtherDriver": {
"Name": "",
"Team": "",
"Nation": "",
"Guid": "",
"GuidsList": null
},
"ImpactSpeed": 22.243214,
"WorldPosition": {
"X": 416.29285,
"Y": 37.574894,
"Z": 849.2622
},
"RelPosition": {
"X": -0.8986338,
"Y": -0.2784356,
"Z": 2.0484245
}
}
]
}
So now I don't really know what I can do against it.
Maybe you guys can help me,
thanks.
So guys, after reading your posts carefully, I got the idea that I just have to wait until the file is written completely. I've done that with a simple Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1000); after that, I can read out the file without a single problem. So, that's the solution for everyone else who stumbles across this problem like me.
Thanks
How is the file created? You probably just have a race condition with the file being created (which triggers the fs.watch event and reading of the file), then the JSON is written after a bit of processing, but it's already too late. Or the JSON is big and it takes time to write it all.
Two options for you:
the process that creates the JSON should work in another directory (but on the same filesystem). Once the file is fully written out, move it to the directory. This way, you have an atomic change, and you know that when you receive the event the file is complete.
An alternative is to write in the same directory, but rename once finished, and have a convention for what files are temporary or final (e.g. if the file is .xxxx.tmp ignore the event).
or whenever you receive an event for a file (rename or change):
cancel any previously created timer for that file
create a new timer for that file
when the timer expires, actually read the file

Cannot read JSON in pandas

I have a nested JSON. I want it to be read in pandas in order to explore it, but I got errors. When to use read_json method, I got: "Trailing data". It is valid JSON. How to read it in pd? (Tried differently, but did not work). It looks like this:
{
"contributors": null,
"coordinates": null,
"created_at": "Fri May 26 08:54:00 +0000 2017",
"entities": {
"hashtags": [],
"media": [
{
"display_url": "pic.twitter.com/Pm28ORTePl",
"expanded_url": "",
"id": 868027417121751040,
"id_str": "868027417121751040",
"indices": [
94,
117
],
"media_url": "",
"sizes": {
"large": {
"h": 404,
"resize": "fit",
"w": 773
},
"medium": {
"h": 404,
"resize": "fit",
"w": 773
},
"small": {
"h": 355,
"resize": "fit",
"w": 680
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"type": "photo",
"url": ""
}
],
"symbols": [],
"urls": [
{
"display_url": "",
"expanded_url": "",
"indices": [
70,
93
],
"url": ""
}
],
"user_mentions": []
},
"extended_entities": {
"media": [
{
"display_url": "pic.twitter.com/Pm28ORTePl",
"expanded_url": "1",
"id": 868027417121751040,
"id_str": "868027417121751040",
"indices": [
94,
117
],
"media_url": "",
"media_url_https": "",
"sizes": {
"large": {
"h": 404,
"resize": "fit",
"w": 773
},
"medium": {
"h": 404,
"resize": "fit",
"w": 773
},
"small": {
"h": 355,
"resize": "fit",
"w": 680
},
"thumb": {
"h": 150,
"resize": "crop",
"w": 150
}
},
"type": "photo",
"url": ""
}
]
},
"favorite_count": 1,
"favorited": false,
"geo": null,
"id": 868027425757724672,
"id_str": "868027425757724672",
"in_reply_to_screen_name": null,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"is_quote_status": false,
"lang": "ru",
"place": null,
"possibly_sensitive": false,
"retweet_count": 0,
"retweeted": false,
"source": "Twitter Web Client",
"text": "\u041f\u0440\u043e\u043f\u0430\u0432\u0448\u0430\u044f \u0432 \u041a\u043e\u043a\u0448\u0435\u0442\u0430\u0443 \u0448\u043a\u043e\u043b\u044c\u043d\u0438\u0446\u0430 \u0436\u0438\u043b\u0430 \u0432 \u0437\u0430\u0431\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u043c \u0434\u043e\u043c\u0435 \u0438 \u0431\u0440\u043e\u0434\u044f\u0436\u043d\u0438\u0447\u0430\u043b\u0430\n",
"truncated": false,
"user": {
"contributors_enabled": false,
"created_at": "Wed May 18 11:59:50 +0000 2011",
"default_profile": true,
"default_profile_image": false,
"description": "\u041a\u0430\u0437\u0430\u0445\u0441\u0442\u0430\u043d\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442-\u043f\u043e\u0440\u0442\u0430\u043b",
"entities": {
"description": {
"urls": []
},
"url": {
"urls": [
{
"display_url": "",
"expanded_url": "",
"indices": [
0,
22
],
"url": ""
}
]
}
},
"favourites_count": 87,
"follow_request_sent": false,
"followers_count": 17989,
"following": true,
"friends_count": 98,
"geo_enabled": true,
"has_extended_profile": false,
"id": 300811189,
"id_str": "300811189",
"is_translation_enabled": false,
"is_translator": false,
"lang": "ru",
"listed_count": 86,
"location": "\u0410\u043b\u043c\u0430\u0442\u044b",
"name": "",
"notifications": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_banner_url": "https://pbs.twimg.com/profile_banners/300811189/1489117916",
"profile_image_url": "http://pbs.twimg.com/profile_images/840047424882298881/NxZSyfhM_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/840047424882298881/NxZSyfhM_normal.jpg",
"profile_link_color": "1DA1F2",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"protected": false,
"screen_name": "",
"statuses_count": 53011,
"time_zone": "Quito",
"translator_type": "none",
"url": "",
"utc_offset": -18000,
"verified": false
}
}
Sorry, but your JSON is actually not valid, despite your saying it is.
This line:
"media_url": "": "",
Should probably be:
"media_url": "",
At which point, when I added the final bracket } that was outside of your code block, validated as properly formed JSON.

parsing a large multi nested json into scala case class

Below is a json example of Twitter's tweet. It's a large json. What is the best library/method to parse it into a case class in scala?
For instance, in Play Framework 2.x it's possible to do that with it's internal library by defining case classes and implicit conversions, but in this case I don't use Play. Should I?
spray-json seems to be most popular scala json library, but in this case it looks quite disappointing - standard approach seems to be limited to 22 elements and uses pattern matching, which becomes ridiculous in the context of multi nested structure with hundreds of elements. Any ideas?
{
"created_at": "Sat Oct 24 06:44:34 +0000 2015",
"id": 657809891558576132,
"id_str": "657809891558576132",
"text": "RT #M23projects: Kara Walker \"Go to Hell or Atlanta, Whichever Come First\" #victoriamiro #London https://t.co/HapqKa4i0l https://t.co/95G…",
"source": "Twitter for iPhone",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 2792146884,
"id_str": "2792146884",
"name": "Tonbridge School Art",
"screen_name": "ArtTonSchool",
"location": "Tonbridge",
"url": null,
"description": "Tonbridge School is an independent day and boarding school for boys. Tweets by the Art Department.",
"protected": false,
"verified": false,
"followers_count": 187,
"friends_count": 288,
"listed_count": 10,
"favourites_count": 1069,
"statuses_count": 1764,
"created_at": "Fri Sep 05 15:37:43 +0000 2014",
"utc_offset": 3600,
"time_zone": "London",
"geo_enabled": true,
"lang": "en-gb",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "C0DEED",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_link_color": "0084B4",
"profile_sidebar_border_color": "C0DEED",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"profile_image_url": "http://pbs.twimg.com/profile_images/507921409738543104/V35eZACR_normal.jpeg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/507921409738543104/V35eZACR_normal.jpeg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/2792146884/1410119421",
"default_profile": true,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"retweeted_status": {
"created_at": "Sat Oct 24 02:27:06 +0000 2015",
"id": 657745100739506176,
"id_str": "657745100739506176",
"text": "Kara Walker \"Go to Hell or Atlanta, Whichever Come First\" #victoriamiro #London https://t.co/HapqKa4i0l https://t.co/95GaLC4XTo",
"source": "Twitter for iPhone",
"truncated": false,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 999716342,
"id_str": "999716342",
"name": "M23",
"screen_name": "M23projects",
"location": "New York",
"url": "http://M23.co",
"description": "M23's project space + itinerant program promotes new work by new artists. \nhttp://Instagram.com/m23projects",
"protected": false,
"verified": false,
"followers_count": 9150,
"friends_count": 7353,
"listed_count": 174,
"favourites_count": 1354,
"statuses_count": 4666,
"created_at": "Sun Dec 09 17:13:35 +0000 2012",
"utc_offset": -14400,
"time_zone": "Eastern Time (US & Canada)",
"geo_enabled": true,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "547587",
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/884257252/e329bbc1b91d695862d5b23a209f2d34.jpeg",
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/884257252/e329bbc1b91d695862d5b23a209f2d34.jpeg",
"profile_background_tile": true,
"profile_link_color": "414A4D",
"profile_sidebar_border_color": "FFFFFF",
"profile_sidebar_fill_color": "DDEEF6",
"profile_text_color": "333333",
"profile_use_background_image": true,
"profile_image_url": "http://pbs.twimg.com/profile_images/458985956830236673/Z_4Bq9PJ_normal.jpeg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/458985956830236673/Z_4Bq9PJ_normal.jpeg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/999716342/1398650659",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 2,
"favorite_count": 3,
"entities": {
"hashtags": [
{
"text": "London",
"indices": [
74,
81
]
}
],
"urls": [
{
"url": "https://t.co/HapqKa4i0l",
"expanded_url": "http://instagram.com/m23projects",
"display_url": "instagram.com/m23projects",
"indices": [
82,
105
]
}
],
"user_mentions": [
{
"screen_name": "victoriamiro",
"name": "Victoria Miro",
"id": 373924746,
"id_str": "373924746",
"indices": [
58,
71
]
}
],
"symbols": [],
"media": [
{
"id": 657745078413201408,
"id_str": "657745078413201408",
"indices": [
106,
129
],
"media_url": "http://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 255,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 450,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
}
}
}
]
},
"extended_entities": {
"media": [
{
"id": 657745078413201408,
"id_str": "657745078413201408",
"indices": [
106,
129
],
"media_url": "http://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 255,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 450,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
}
}
},
{
"id": 657745085275095040,
"id_str": "657745085275095040",
"indices": [
106,
129
],
"media_url": "http://pbs.twimg.com/media/CSDHq5CUwAAC-6a.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHq5CUwAAC-6a.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 453,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 800,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 768,
"h": 1024,
"resize": "fit"
}
}
},
{
"id": 657745085300277248,
"id_str": "657745085300277248",
"indices": [
106,
129
],
"media_url": "http://pbs.twimg.com/media/CSDHq5IVAAAn2YH.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHq5IVAAAn2YH.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 453,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 800,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 768,
"h": 1024,
"resize": "fit"
}
}
},
{
"id": 657745085275082752,
"id_str": "657745085275082752",
"indices": [
106,
129
],
"media_url": "http://pbs.twimg.com/media/CSDHq5CUkAAd0oL.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHq5CUkAAd0oL.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 255,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 450,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
}
}
}
]
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "en"
},
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [
{
"text": "London",
"indices": [
91,
98
]
}
],
"urls": [
{
"url": "https://t.co/HapqKa4i0l",
"expanded_url": "http://instagram.com/m23projects",
"display_url": "instagram.com/m23projects",
"indices": [
99,
122
]
}
],
"user_mentions": [
{
"screen_name": "M23projects",
"name": "M23",
"id": 999716342,
"id_str": "999716342",
"indices": [
3,
15
]
},
{
"screen_name": "victoriamiro",
"name": "Victoria Miro",
"id": 373924746,
"id_str": "373924746",
"indices": [
75,
88
]
}
],
"symbols": [],
"media": [
{
"id": 657745078413201408,
"id_str": "657745078413201408",
"indices": [
123,
140
],
"media_url": "http://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 255,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 450,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
}
},
"source_status_id": 657745100739506176,
"source_status_id_str": "657745100739506176",
"source_user_id": 999716342,
"source_user_id_str": "999716342"
}
]
},
"extended_entities": {
"media": [
{
"id": 657745078413201408,
"id_str": "657745078413201408",
"indices": [
123,
140
],
"media_url": "http://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHqfeUkAA4a0Y.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 255,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 450,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
}
},
"source_status_id": 657745100739506176,
"source_status_id_str": "657745100739506176",
"source_user_id": 999716342,
"source_user_id_str": "999716342"
},
{
"id": 657745085275095040,
"id_str": "657745085275095040",
"indices": [
123,
140
],
"media_url": "http://pbs.twimg.com/media/CSDHq5CUwAAC-6a.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHq5CUwAAC-6a.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 453,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 800,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 768,
"h": 1024,
"resize": "fit"
}
},
"source_status_id": 657745100739506176,
"source_status_id_str": "657745100739506176",
"source_user_id": 999716342,
"source_user_id_str": "999716342"
},
{
"id": 657745085300277248,
"id_str": "657745085300277248",
"indices": [
123,
140
],
"media_url": "http://pbs.twimg.com/media/CSDHq5IVAAAn2YH.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHq5IVAAAn2YH.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 453,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 800,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 768,
"h": 1024,
"resize": "fit"
}
},
"source_status_id": 657745100739506176,
"source_status_id_str": "657745100739506176",
"source_user_id": 999716342,
"source_user_id_str": "999716342"
},
{
"id": 657745085275082752,
"id_str": "657745085275082752",
"indices": [
123,
140
],
"media_url": "http://pbs.twimg.com/media/CSDHq5CUkAAd0oL.jpg",
"media_url_https": "https://pbs.twimg.com/media/CSDHq5CUkAAd0oL.jpg",
"url": "https://t.co/95GaLC4XTo",
"display_url": "pic.twitter.com/95GaLC4XTo",
"expanded_url": "http://twitter.com/M23projects/status/657745100739506176/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 340,
"h": 255,
"resize": "fit"
},
"medium": {
"w": 600,
"h": 450,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
}
},
"source_status_id": 657745100739506176,
"source_status_id_str": "657745100739506176",
"source_user_id": 999716342,
"source_user_id_str": "999716342"
}
]
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "en",
"timestamp_ms": "1445669074321"
}
**UPDATE: ** I guess I should stick to play-json, even more so for performance reasons - http://derekwyatt.org/2014/01/15/benchmarking-spray-json-argonaut-play-json/
You can depends on Play's JSON library by itself:
// build.sbt
libraryDependencies += "com.typesafe.play" % "play-json_2.11" % "X.X.X"
// Tweet.scala
import play.api.libs.json._
case class User(id: String, name: String, ...)
implicit val userFormat = Json.format[User]
case class Tweet(id: String, content: String, user: User)
implicit val tweetFormat = Json.format[Tweet]
This will use play-json's macros to auto-generate the formatters you need to parse JSON into instances of Tweet and User.
Regardless of library you choose you won't find an elegant solution for handling more than 22 fields since that's a limitation of the case class implementation (up until 2.11) rather than any specific design choice by a library.