Something wrong with format of json - json

I am using this json data
{
"type":"Polygon",
"coordinates":[[[72.8282833,19.0175056],[72.8285408,19.017849],[72.8292274,19.0185356],[72.8302574,19.0188789],[72.8309441,19.0195656],[72.8311157,19.0200806],[72.8311157,19.0207672],[72.8312874,19.0212822],[72.833004,19.0229988],[72.8333473,19.0240288],[72.8336906,19.0243721],[72.834034,19.0254021],[72.8343773,19.0257454],[72.8347206,19.0267754],[72.8350639,19.0271187],[72.8354073,19.0281487],[72.8357506,19.028492],[72.8357506,19.0288353],[72.8354073,19.0291786],[72.8352356,19.0296936],[72.8352356,19.0303802],[72.8354073,19.0308952],[72.8357506,19.0312386],[72.8360939,19.0322685],[72.8371239,19.0326118],[72.8374672,19.0329552],[72.8379822,19.0331268],[72.8384972,19.0329552],[72.8388405,19.0326118],[72.8393555,19.0324402],[72.8398705,19.0326118],[72.8412437,19.0339851],[72.8415871,19.0350151],[72.8422737,19.0357018],[72.8427887,19.0358734],[72.8434753,19.0358734],[72.8439903,19.0360451],[72.8443336,19.0363884],[72.8448486,19.0365601],[72.8455353,19.0365601],[72.8460503,19.0367317],[72.8463936,19.037075],[72.8474236,19.0374184],[72.8475952,19.0379333],[72.8475952,19.0399933],[72.8474236,19.0405083],[72.8469086,19.0406799],[72.8462219,19.0406799],[72.8457069,19.0408516],[72.8453636,19.0418816],[72.8439903,19.0432549],[72.8434753,19.0434265],[72.8427887,19.0434265],[72.8422737,19.0435982],[72.8419304,19.0439415],[72.8414154,19.0441132],[72.8400421,19.0441132],[72.8395271,19.0442848],[72.8393555,19.0447998],[72.8393555,19.0468597],[72.8395271,19.0473747],[72.8415871,19.0494347],[72.8421021,19.0496063],[72.8427887,19.0496063],[72.8433037,19.0494347],[72.844677,19.0480614],[72.8450203,19.0470314],[72.8455353,19.0468597],[72.8469086,19.0468597],[72.8474236,19.0470314],[72.8477669,19.0473747],[72.8487968,19.047718],[72.8487968,19.0480614],[72.8484535,19.0484047],[72.8481102,19.0494347],[72.8457069,19.0518379],[72.8455353,19.0523529],[72.8455353,19.0537262],[72.8457069,19.0542412],[72.8462219,19.0544128],[72.8475952,19.0544128],[72.8481102,19.0542412],[72.8487968,19.0535545],[72.8491402,19.0525246],[72.8508568,19.050808],[72.8512001,19.049778],[72.8518867,19.0490913],[72.8522301,19.0490913],[72.8525734,19.0494347],[72.8530884,19.0496063],[72.8544617,19.0496063],[72.8549767,19.049778],[72.8563499,19.0511513],[72.8566933,19.0521812],[72.8573799,19.0528679],[72.8578949,19.0530396],[72.8640747,19.0530396],[72.8645897,19.0532112],[72.8652763,19.0538979],[72.865448,19.0544128],[72.865448,19.0550995],[72.8656197,19.0556145],[72.8661346,19.0557861],[72.8668213,19.0557861],[72.8673363,19.0559578],[72.8690529,19.0576744],[72.8695679,19.0578461],[72.8709412,19.0578461],[72.8714561,19.0576744],[72.8717995,19.0573311],[72.8721428,19.0573311],[72.8731728,19.0583611],[72.8736877,19.0585327],[72.8742027,19.0583611],[72.8745461,19.0580177],[72.875061,19.0578461],[72.875576,19.0580177],[72.8759193,19.0590477],[72.8769493,19.059391],[72.8772926,19.060421],[72.877636,19.0607643],[72.8779793,19.0617943],[72.8784943,19.0619659],[72.8798676,19.0619659],[72.8803825,19.0617943],[72.8807259,19.0607643],[72.8814125,19.0600777],[72.8819275,19.059906],[72.8826141,19.059906],[72.8831291,19.0597343],[72.8834724,19.059391],[72.8839874,19.0592194],[72.8845024,19.059391],[72.8848457,19.0597343],[72.8853607,19.059906],[72.8860474,19.059906],[72.8865623,19.0600777],[72.8869057,19.060421],[72.8874207,19.0605927],[72.8879356,19.060421],[72.888279,19.0600777],[72.8886223,19.0600777],[72.8889656,19.060421],[72.8899956,19.0607643],[72.8917122,19.0624809],[72.8922272,19.0626526],[72.8942871,19.0626526],[72.8948021,19.0624809],[72.8949738,19.0619659],[72.8949738,19.0605927],[72.8948021,19.0600777],[72.8937721,19.0597343],[72.8927422,19.0587044],[72.8917122,19.0583611],[72.8896523,19.0563011],[72.8894806,19.0557861],[72.8896523,19.0552711],[72.8906822,19.0549278],[72.8913689,19.0542412],[72.8913689,19.0538979],[72.8906822,19.0532112],[72.8901672,19.0530396],[72.8894806,19.0530396],[72.8889656,19.0528679],[72.8886223,19.0525246],[72.8881073,19.0523529],[72.886734,19.0523529],[72.886219,19.0521812],[72.8858757,19.0518379],[72.8853607,19.0516663],[72.8846741,19.0516663],[72.8841591,19.0518379],[72.8838158,19.0521812],[72.8834724,19.0521812],[72.8833008,19.0516663],[72.8833008,19.0509796],[72.8831291,19.0504646],[72.8827858,19.0501213],[72.8827858,19.049778],[72.8831291,19.0494347],[72.8833008,19.0489197],[72.8833008,19.0454865],[72.8831291,19.0449715],[72.8826141,19.0447998],[72.8784943,19.0447998],[72.8779793,19.0449715],[72.8772926,19.0456581],[72.8769493,19.0466881],[72.8759193,19.047718],[72.875576,19.048748],[72.875061,19.0489197],[72.8736877,19.0489197],[72.8731728,19.048748],[72.8728294,19.0484047],[72.8717995,19.0480614],[72.8714561,19.047718],[72.8704262,19.0473747],[72.8702545,19.0468597],[72.8702545,19.0461731],[72.8700829,19.0456581],[72.8697395,19.0453148],[72.8693962,19.0442848],[72.8690529,19.0439415],[72.8688812,19.0434265],[72.8690529,19.0429115],[72.8700829,19.0418816],[72.8702545,19.0413666],[72.8702545,19.0406799],[72.8700829,19.0401649],[72.8697395,19.0398216],[72.8697395,19.0394783],[72.8700829,19.039135],[72.8704262,19.038105],[72.8709412,19.0379333],[72.8723145,19.0379333],[72.8728294,19.0377617],[72.8735161,19.037075],[72.8736877,19.0365601],[72.8735161,19.0360451],[72.8728294,19.0353584],[72.8723145,19.0351868],[72.8716278,19.0351868],[72.8711128,19.0350151],[72.8711128,19.0346718],[72.8714561,19.0343285],[72.8716278,19.0338135],[72.8716278,19.0324402],[72.8714561,19.0319252],[72.8709412,19.0317535],[72.8695679,19.0317535],[72.8690529,19.0315819],[72.8688812,19.0310669],[72.8688812,19.0303802],[72.8687096,19.0298653],[72.8683662,19.0295219],[72.8681946,19.029007],[72.8683662,19.028492],[72.8697395,19.0271187],[72.8707695,19.0267754],[72.8709412,19.0262604],[72.8709412,19.0255737],[72.8707695,19.0250587],[72.8704262,19.0247154],[72.8704262,19.0243721],[72.8711128,19.0236855],[72.8714561,19.0236855],[72.8717995,19.0240288],[72.8723145,19.0242004],[72.8730011,19.0242004],[72.8735161,19.0240288],[72.8742027,19.0233421],[72.8742027,19.0229988],[72.8738594,19.0226555],[72.8736877,19.0221405],[72.8738594,19.0216255],[72.8743744,19.0214539],[72.875061,19.0214539],[72.875576,19.0212822],[72.8757477,19.0207672],[72.8757477,19.0193939],[72.875576,19.0188789],[72.8752327,19.0185356],[72.8748894,19.0175056],[72.8742027,19.016819],[72.8736877,19.0166473],[72.8730011,19.0166473],[72.8724861,19.0164757],[72.8721428,19.0161324],[72.8716278,19.0159607],[72.8709412,19.0159607],[72.8704262,19.0161324],[72.8700829,19.0164757],[72.8697395,19.0164757],[72.8693962,19.0154457],[72.8687096,19.0147591],[72.8681946,19.0145874],[72.8668213,19.0145874],[72.8663063,19.0144157],[72.8661346,19.0139008],[72.8661346,19.0132141],[72.865963,19.0126991],[72.865448,19.0125275],[72.8647614,19.0125275],[72.8642464,19.0123558],[72.8642464,19.0120125],[72.8652763,19.0116692],[72.865448,19.0111542],[72.865448,19.0097809],[72.8652763,19.0092659],[72.8645897,19.0085793],[72.8635597,19.0082359],[72.8632164,19.0078926],[72.8621864,19.0075493],[72.8618431,19.0065193],[72.8613281,19.0063477],[72.8585815,19.0063477],[72.8580666,19.0065193],[72.8570366,19.0075493],[72.8565216,19.0077209],[72.8560066,19.0075493],[72.855835,19.0070343],[72.8560066,19.0065193],[72.8563499,19.006176],[72.8563499,19.0058327],[72.8560066,19.0054893],[72.855835,19.0049744],[72.8560066,19.0044594],[72.8563499,19.0041161],[72.8563499,19.0037727],[72.8560066,19.0034294],[72.8556633,19.0023994],[72.85532,19.0020561],[72.8551483,19.0015411],[72.8551483,19.0008545],[72.8549767,19.0003395],[72.85429,18.9996529],[72.853775,18.9994812],[72.85326,18.9996529],[72.8525734,19.0003395],[72.8524017,19.0008545],[72.8524017,19.0029144],[72.8522301,19.0034294],[72.8518867,19.0037727],[72.8517151,19.0042877],[72.8517151,19.0049744],[72.8518867,19.0054893],[72.8522301,19.0058327],[72.8524017,19.0063477],[72.8524017,19.0090942],[72.8525734,19.0096092],[72.8529167,19.0099525],[72.8529167,19.0102959],[72.8524017,19.0104675],[72.8518867,19.0102959],[72.8517151,19.0097809],[72.8517151,19.0077209],[72.8515434,19.007206],[72.8512001,19.0068626],[72.8508568,19.0058327],[72.8503418,19.005661],[72.8482819,19.005661],[72.8477669,19.0054893],[72.8475952,19.0049744],[72.8477669,19.0044594],[72.8481102,19.0041161],[72.8482819,19.0036011],[72.8482819,19.0015411],[72.8484535,19.0010262],[72.8487968,19.0006828],[72.8489685,19.0001678],[72.8487968,18.9996529],[72.8477669,18.9986229],[72.8475952,18.9981079],[72.8475952,18.9974213],[72.8474236,18.9969063],[72.8469086,18.9967346],[72.8448486,18.9967346],[72.8443336,18.996563],[72.843647,18.9958763],[72.8434753,18.9953613],[72.8434753,18.9946747],[72.8433037,18.9941597],[72.842617,18.9934731],[72.8421021,18.9933014],[72.8414154,18.9933014],[72.8409004,18.9931297],[72.8405571,18.9920998],[72.8395271,18.9917564],[72.8395271,18.9914131],[72.8398705,18.9910698],[72.8398705,18.9907265],[72.8384972,18.9893532],[72.8374672,18.9890099],[72.8372955,18.9884949],[72.8372955,18.9857483],[72.8371239,18.9852333],[72.8367805,18.98489],[72.8366089,18.984375],[72.8366089,18.9823151],[72.8364372,18.9818001],[72.8360939,18.9814568],[72.8359222,18.9809418],[72.8359222,18.9802551],[72.8357506,18.9797401],[72.8354073,18.9793968],[72.8352356,18.9788818],[72.8352356,18.9768219],[72.8350639,18.9763069],[72.834549,18.9761353],[72.8331757,18.9761353],[72.8326607,18.9763069],[72.832489,18.9768219],[72.832489,18.9802551],[72.8326607,18.9807701],[72.833004,18.9811134],[72.8331757,18.9816284],[72.8331757,18.9823151],[72.8333473,18.98283],[72.8336906,18.9831734],[72.8338623,18.9836884],[72.8338623,18.9864349],[72.834034,18.9869499],[72.8343773,18.9872932],[72.834549,18.9878082],[72.8343773,18.9883232],[72.8333473,18.9886665],[72.8331757,18.9891815],[72.8331757,18.9912415],[72.8333473,18.9917564],[72.8343773,18.9920998],[72.8347206,18.9931297],[72.8350639,18.9934731],[72.8350639,18.9938164],[72.834034,18.9941597],[72.8338623,18.9946747],[72.8338623,18.996048],[72.834034,18.996563],[72.8347206,18.9972496],[72.8357506,18.9975929],[72.8359222,18.9981079],[72.8359222,18.9987946],[72.8360939,18.9993095],[72.8364372,18.9996529],[72.8366089,19.0001678],[72.8366089,19.0015411],[72.8367805,19.0020561],[72.8371239,19.0023994],[72.8372955,19.0029144],[72.8371239,19.0034294],[72.8360939,19.0044594],[72.8357506,19.0054893],[72.8354073,19.0058327],[72.8352356,19.0063477],[72.8352356,19.0077209],[72.8354073,19.0082359],[72.8359222,19.0084076],[72.8372955,19.0084076],[72.8378105,19.0082359],[72.8381538,19.0078926],[72.8384972,19.0078926],[72.8386688,19.0084076],[72.8386688,19.0090942],[72.8388405,19.0096092],[72.8398705,19.0099525],[72.8402138,19.0109825],[72.8405571,19.0113258],[72.8407288,19.0118408],[72.8407288,19.0139008],[72.8405571,19.0144157],[72.8402138,19.0144157],[72.8395271,19.0137291],[72.8391838,19.0126991],[72.8378105,19.0113258],[72.8372955,19.0111542],[72.8359222,19.0111542],[72.8354073,19.0113258],[72.8347206,19.0120125],[72.8347206,19.0123558],[72.8350639,19.0126991],[72.8350639,19.0130424],[72.8347206,19.0133858],[72.8343773,19.0144157],[72.8338623,19.0145874],[72.8331757,19.0145874],[72.8326607,19.0147591],[72.8323174,19.0151024],[72.8312874,19.0154457],[72.8309441,19.015789],[72.8306007,19.015789],[72.8295708,19.0147591],[72.8290558,19.0145874],[72.8285408,19.0147591],[72.8278542,19.0154457],[72.8276825,19.0159607],[72.8276825,19.0166473],[72.8277683,19.0171623],[72.8282833,19.017]]]
}
to plot on http://geojson.io/
Is it a syntax error?

Please try this i have ploted the polygon on googlemap and the syntax i got as following
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
61.17187499999999,
59.712097173322924
],
[
116.01562499999999,
59.5343180010956
],
[
136.40625,
41.77131167976407
],
[
116.3671875,
10.487811882056683
],
[
71.015625,
6.315298538330033
],
[
36.2109375,
23.88583769986199
],
[
61.17187499999999,
59.712097173322924
]
]
]
}
}
]
}
link to the polygon which i have created
https://gist.github.com/anonymous/4f79e65b677f7171c7b1

Related

scala ujson.read() returns ujson.Obj

I am trying to read a json string using Li Haoyi's ujson. This is the string:
{
"dataflows": [
{
"name": "test",
"sources": [
{
"name": "person_inputs",
"path": "/data/input/events/person/*",
"format": "JSON"
}
],
"transformations": [
{
"name": "validation",
"type": "validate_fields",
"params": {
"input": "person_inputs",
"validations": [
{
"field": "office",
"validations": [
"notEmpty"
]
},
{
"field": "age",
"validations": [
"notNull"
]
}
]
}
},
{
"name": "ok_with_date",
"type": "add_fields",
"params": {
"input": "validation_ok",
"addFields": [
{
"name": "dt",
"function": "current_timestamp"
}
]
}
}
],
"sinks": [
{
"input": "ok_with_date",
"name": "raw-ok",
"paths": [
"/data/output/events/person"
],
"format": "JSON",
"saveMode": "OVERWRITE"
},
{
"input": "validation_ko",
"name": "raw-ko",
"paths": [
"/data/output/discards/person"
],
"format": "JSON",
"saveMode": "OVERWRITE"
}
]
}
]
}
And this is how I read it:
val j = os.read(os.pwd/RelPath("src/main/scala/metadata.json"))
val jsonData = ujson.read(j)
But, the return type is ujson.Obj, and not Arr(ArrayBuffer(Obj), as expected, such that when I try to get jsonData(0), what I get is json.Value$InvalidData: Expected ujson.Arr.
I am asking this question because I have tried to use the ujson object to create a upickle object, but I cannot, and I suspect it is because of this initial error.
Any ideas of why this happens? Any help would be greatly appreciated! Thanks in advance!!
The outer element of your JSON is not an array, it is an object with a single element dataflows whose value is an array. Try jsonData("dataflows")(0).

Algorithm to merge two JSON

I'm out of my wits trying to figure out how I can merge two JSON I have representing permissions into one. I have a default role that outlines the full extent of the hierarchy and when I merge it with other json, I need to pass on the parent assigned permissions to it's children if they were missing.
Default permission:
{
"id": "default-role",
"entities": [
{
"name": "entry",
"permissions": [
"read"
],
"fields": [
{
"name": "address",
"permissions": [
"read"
],
"fields": [
{
"name": "zipcode",
"permissions": [
"read"
]
}
]
}
]
}
]
}
Custom Permissions:
{
"id": "admin",
"entities": [
{
"name": "entry",
"permissions": [
"read", "write"
]
}
]
}
Merged expected output:
{
"id": "defaultRole",
"entities": [
{
"name": "entry",
"permissions": [
"read", "write"
],
"fields": [
{
"name": "address",
"permissions": [
"read", "write"
],
"fields": [
{
"name": "zipcode",
"permissions": [
"read", "write"
]
}
]
}
]
}
]
}

Load GeoJSON file into redshift using copy command

I have a file containing spatial data that I would like to load into Tableau using AWS. I found documentation that Amazon Redshift supports GeoJSON data through the GEOMETRY data type. I managed to upload the data into an S3 bucket and to create a table in my Redshift cluster through the following query:
CREATE TABLE public.data (
PC6 VARCHAR(100),
Aantal_adr INTEGER,
geometry GEOMETRY,
Gemeente2019 INTEGER,
Wijk2019 INTEGER,
Buurt2019 INTEGER
);
However, when I want to load the GeoJSON file from S3 into the table, the table remains empty and I don't even get an error. How do I get it to work?
I used the following command:
COPY public.data
FROM 's3://path/folder/data.json'
CREDENTIALS 'aws_access_key_id=x;aws_secret_access_key=y'
json 'auto'
region 'eu-west-1';
And this is a sample of my data:
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "PC6": "1011AB", "Aantal_adr": 32, "Gemeente2019": 363, "Wijk2019": 36304, "Buurt2019": 3630400 }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 4.905027952000069, 52.378425486000026 ], [ 4.905076113000064, 52.37841046300008 ], [ 4.905191411000033, 52.378376782000032 ], [ 4.905214767000075, 52.378369010000029 ], [ 4.905234707000034, 52.378360745000066 ], [ 4.905242522000037, 52.37835616600006 ], [ 4.905248247000031, 52.37835098000005 ], [ 4.905251343000032, 52.378345312000079 ], [ 4.905252578000045, 52.378339070000038 ], [ 4.905252531000031, 52.378332431000047 ], [ 4.905249474000072, 52.378312360000052 ], [ 4.905248898000025, 52.378300391000039 ], [ 4.905250074000037, 52.378294856000082 ], [ 4.905252799000039, 52.378289789000064 ], [ 4.905257110000036, 52.37828554400005 ], [ 4.905262918000062, 52.378281792000053 ], [ 4.905272242000024, 52.378277568000044 ], [ 4.905295016000025, 52.378270656000041 ], [ 4.905320961000029, 52.378264933000082 ], [ 4.90534841300007, 52.378259781000054 ], [ 4.905615848000025, 52.378213457000072 ], [ 4.905672094000067, 52.378204254000082 ], [ 4.905713623000054, 52.378198448000035 ], [ 4.905755373000034, 52.378193294000027 ], [ 4.905797334000056, 52.378188918000035 ], [ 4.905854017000024, 52.378184793000059 ], [ 4.906010385000059, 52.378175414000054 ], [ 4.906049546000077, 52.378171835000046 ], [ 4.906099170000061, 52.378165687000035 ], [ 4.906138697000074, 52.378159097000037 ], [ 4.906179196000039, 52.378151124000055 ], [ 4.906393302000026, 52.378105836000032 ], [ 4.906379850000064, 52.378077200000064 ], [ 4.906376915000067, 52.37806777000003 ], [ 4.906375354000033, 52.37805852300005 ], [ 4.906375845000071, 52.37805008600003 ], [ 4.906379084000037, 52.378043095000066 ], [ 4.906385125000043, 52.378038245000027 ], [ 4.906393308000077, 52.378034955000032 ], [ 4.906413366000038, 52.378029843000036 ], [ 4.906448001000058, 52.378023854000048 ], [ 4.906689757000038, 52.377990125000053 ], [ 4.906724868000026, 52.37798340900008 ], [ 4.906734994000033, 52.377980573000059 ], [ 4.90674369200002, 52.377977198000053 ], [ 4.906750343000056, 52.377973046000079 ], [ 4.906754179000075, 52.377967886000079 ], [ 4.90675559500005, 52.37796090900008 ], [ 4.906755038000028, 52.377952553000057 ], [ 4.906749900000023, 52.377933764000034 ], [ 4.906733622000047, 52.377896754000062 ], [ 4.906462646000023, 52.377214200000026 ], [ 4.906126387000029, 52.377292057000034 ], [ 4.905688946000055, 52.377410774000055 ], [ 4.905016945000057, 52.377587847000029 ], [ 4.90462009700002, 52.377724772000079 ], [ 4.904597594000052, 52.377732947000027 ], [ 4.904546418000052, 52.377751543000045 ], [ 4.904483645000028, 52.377774349000049 ], [ 4.904388632000064, 52.377808869000035 ], [ 4.904220272000032, 52.377870038000026 ], [ 4.904280897000035, 52.377932213000065 ], [ 4.904695869000022, 52.378344313000071 ], [ 4.904749813000024, 52.378331915000047 ], [ 4.904708505000031, 52.378356860000054 ], [ 4.904782821000026, 52.378430663000074 ], [ 4.904842127000052, 52.378489556000034 ], [ 4.905027952000069, 52.378425486000026 ] ] ] } } ] }
Loading GeoJSON directly into a GEOMETRY column is not currently supported. However, we will consider adding to our roadmap. When new features are released they are noted in our regular maintenance announcements at the top of the forum.
You can only COPY to GEOMETRY columns from data in text or CSV format. The data must be in the hexadecimal form of the extended well-known binary (EWKB) format …
https://docs.aws.amazon.com/redshift/latest/dg/copy-usage_notes-spatial-data.html

Extract from json with | jq by a given word

Can somebody help me to extract with | jq the following:
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"pod": "dev-cds-5c97cf7f78-sw6b9"
},
"values": [
[
1588204800,
"0.3561394483796914"
],
[
1588215600,
"0.3607968456046861"
],
[
1588226400,
"0.3813882532417868"
],
[
1588237200,
"0.6264355815408573"
]
]
},
{
"metric": {
"pod": "uat-cds-66ccc9685-b5tvh"
},
"values": [
[
1588204800,
"0.9969746974696218"
],
[
1588215600,
"0.7400881057270005"
],
[
1588226400,
"1.2298959318837195"
],
[
1588237200,
"0.9482296838254507"
]
]
}
]
}
}
I need to obtain all-values individually by given word dev-cds and not all the name dev-cds-5c97cf7f78-sw6b9.
Result desired:
{
"metric": {
"pod": "dev-cds-5c97cf7f78-sw6b9"
},
"values": [
[
1588204800,
"0.3561394483796914"
],
[
1588215600,
"0.3607968456046861"
],
[
1588226400,
"0.3813882532417868"
],
[
1588237200,
"0.6264355815408573"
]
]
}
You should first iterate over the result array. Check if the pod inside, metric object has the value that contains "dev-cds".
.data.result[] | if .metric.pod | contains("dev-cds") then . else empty end
https://jqplay.org/s/54OH83qHKP

Invalid response of JSON data from Django QuerySet

With this query:
def high_hazard(request):
reference_high = FloodHazard.objects.filter(hazard='High')
ids_high = reference_high.values_list('id', flat=True)
flood_hazard = []
djf = Django.Django(geodjango='geom', properties=['bldg_name', 'bldg_type'])
geoj = GeoJSON.GeoJSON()
for myid in ids_high:
getgeom = FloodHazard.objects.get(id=myid).geom
response_high = BuildingStructure.objects.filter(geom__intersects=getgeom)
get_hazard = geoj.encode(djf.decode(response_high.transform(900913)))
flood_hazard.append(get_hazard)
return HttpResponse(flood_hazard, content_type='application/json')
I was able to filter the BuildingStructure model based on FloodHazard type which is in this case with "high" value. Although it returns a JSON data, the output is messed up. I guess because it tests all the geometry from the FloodHazard model during loop. So, it returns several null set or empty and lots of FeatureCollection which makes it an invalid JSON data. The output of the query above is like this:
{
"crs": null,
"type": "FeatureCollection",
"features": [
]
}{
"crs": null,
"type": "FeatureCollection",
"features": [
]
}{
"crs": null,
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "MultiPoint",
"coordinates": [
[
13974390.863509608,
1020340.6129766875
]
]
},
"type": "Feature",
"id": 3350,
"properties": {
"bldg_name": "",
"bldg_type": ""
}
},
{
"geometry": {
"type": "MultiPoint",
"coordinates": [
[
13974400.312472697,
1020356.5477410051
]
]
},
"type": "Feature",
"id": 3351,
"properties": {
"bldg_name": "",
"bldg_type": ""
}
}
]
}
As I test it with a JSON validator, it is invalid. So, is there a way to restructure(using underscore.js or jquery) this JSON to output like below? or I need to change my query?
{
"crs": null,
"type": "FeatureCollection",
"features": [
{
"geometry": {
"type": "MultiPoint",
"coordinates": [
[
13974390.863509608,
1020340.6129766875
]
]
},
"type": "Feature",
"id": 3350,
"properties": {
"bldg_name": "",
"bldg_type": ""
}
},
{
"geometry": {
"type": "MultiPoint",
"coordinates": [
[
13974400.312472697,
1020356.5477410051
]
]
},
"type": "Feature",
"id": 3351,
"properties": {
"bldg_name": "",
"bldg_type": ""
}
}
]
}
and just ignore/remove all the FeatureCollection without values and group all with values. Here is the result of the query above for reference.
Instead of
return HttpResponse(flood_hazard, content_type='application/json')
Try
return HttpResponse(json.dumps(flood_hazard), content_type='application/json')
You will have to import json at the top.