I have this json:
"client":{
"datas": {
"number1": 14,
"number2": 2,
"number3": 1,
"city": [
"paris",
"tokyo",
"nyc",
"london"
]
},
}
I want to extract label/value peers for the "number" labels but not for the array like that:
number 1 : 14
number 2 : 2
numer 3 : 1
paris,
tokyo,
nyc,
london
Edit:
I tried this loop:
for (i in datas)
{ newDatas = clents.datas[i]; }
I get :
14
2
1
Array [
"paris",
"tokyo",
"nyc",
"london", ]
Related
Iwas able to transform data but not getting the desired output
filter (which i tried):
[inputs | {author , totalpages : .pages , books : [{"title": .title, "year" : .year }] } ] | sort
Input :
{"title":"War of the worlds","author":"H G Wells","year":1896,"pages":203}
{"title":"The invisible man","author":"H G Wells","year":1895,"pages":2136}
{"title":"The Lost World","author":"A C Doyle","year":1912,"pages":185}
{"title":"A Study in Scarlet","author":"A C Doyle","year":1887,"pages":251}
{"title":"20,000 leagues under the sea","author":"J Verne","year":1870,"pages":450}
output should be:
{
"author": "A C Doyle",
"totalpages": 436,
"books": [
{
"title": "The Lost World",
"year": 1912
},
{
"title": "A Study in Scarlet",
"year": 1887
}
]
}
{
"author": "H G Wells",
"totalpages": 2339,
"books": [
{
"title": "War of the worlds",
"year": 1896
},
{
"title": "The invisible man",
"year": 1895
}
]
}
{
"author": "J Verne",
"totalpages": 450,
"books": [
{
"title": "20,000 leagues under the sea",
"year": 1870
}
]
}
Just a series of transformation is all is required, starting with group_by()
jq -n '
[ inputs ] |
group_by(.author) |
map
(
{
author: .[0].author,
totalpages: ( map(.pages) | add ),
books: ( map( { title, year } ) )
}
)'
jqplay - demo
Below part is my json encode data,
[
{
project_name: "Faithview 1 Residence",
BookedUnit: "25",
GDV: "9,143,860.00"
},
{
project_name: "Faithview 2 Residence",
BookedUnit: "24", GDV: "8,795,380.00"
},
{
project_name: "Faithview 3 Residence",
BookedUnit: "24",
GDV: "8,795,380.00"
}
]
I would like to change the json data become like this as shown below:-
[
{
project_name: "Faithview 1 Residence",
Unit: 25
},
{
project_name: "Faithview 2 Residence",
Unit: 24
},
{
project_name: "Faithview 3 Residence",
Unit: 24
}
]
There is 3 condition in the new json data which is :-
1) Delete the GDV
2) The key of BookedUnit change to Unit.
3) The format value of "Unit" now become Int.
Any suggestion and solution is appreciated.
Please check this solution.This is work for you
var oldJSON = [{project_name: "Faithview 1 Residence", BookedUnit: "25", GDV: "9,143,860.00"} , {project_name: "Faithview 2 Residence", BookedUnit: "24", GDV: "8,795,380.00"} , {project_name: "Faithview 3 Residence", BookedUnit: "24", GDV: "8,795,380.00"}];
var newJSON = [];
for(key in oldJSON){
newJSON[key] = {project_name : oldJSON[key].project_name, Unit : parseInt(oldJSON[key].BookedUnit)};
}
console.log(newJSON);
I have a json like this:
[
{
"ser": 345,
"City": "New York",
"Gen": 1
},
{
"ser": 55,
"City": "New York",
"Gen": 2
},
{
"ser": 19,
"City": "New York",
"Gen": 3
}
]
I want to make some query to this json ( example: SELECT SUM(ser) AS Serlab, City, Gen FROM libri GROUP BY City, Gen ORDER BY City)...i need spark rdd to make this.
After this query i should modify the structure of my input json in this new:
[ { "label": [1,2,3] //that is the Gen value,
"values": [
{ "label":"New York"
"values":["200","10","66"] //is the ser about all Gen (for eexample 200 is ser is for label/gen 1 .. 10 is for label/gen 2 etc.
},
{ "label":"London"
"values":["500","150","46"]
},
{ "label":"London"
"values":["500","150","46"]
},
.
.
.
.
.
]
}
]
And then i send this new JSON to a Http request
How can i make this in scala,play,spark? Please help me :)
I have two tables which are as follows:
quote_glass_types
id | name
1 clear float glass
2 Tinted glass
quote_glass_type_thickness
id | quote_glass_type_id_fk | thickness
1 1 5mm
2 1 8mm
3 2 5mm
4 2 8mm
Now, I would like to join these two tables and get Json as follows:
[
{
id:1,
name: "clear float glass",
thickness:{"5mm","8mm" }
},
{
id:2
name:"tinted glass",
thickness:{"5mm","8mm"}
}
]
Till now I have done like this:
$glasssetting=\DB::table('quote_glass_types')
->join('quote_glass_type_thickness','quote_glass_type_thickness.quote_glass_type_id_fk','=','quote_glass_types.id')
->select('quote_glass_type_thickness.id','name','thickness')
->get();
return $glasssetting;
which gives JSON like:
[
{
"id": 1,
"name": "Clear Float Glasss",
"thickness": "5mm"
},
{
"id": 2,
"name": "Clear Float Glasss",
"thickness": "8mm"
},
{
"id": 3,
"name": "Tinted glass",
"thickness": "5mm"
},
{
"id": 4,
"name": "Tinted glass",
"thickness": "8mm"
}
]
How do I get the required json?
Just use Eloquent for example
return App\QuoteGlassType::with('thickness')->get();
I dont know your Modelname but thats what you are looking for.
Of course make also sure to set the correct Relationships within your Model.
I have a sample json data like:
{
"phone_number": "780-414-2085",
"city": "Edmonton",
"updated": "2015-10-19T00:03:10",
"name": "Sir William Place ",
"url": "http://www.bwalk.com/en-CA/Rent/Details/Alberta/Edmonton/Sir-William-Place",
"last_visited": "2015-10-19T00:03:10",
"rooms": [{
"available": "Available",
"bathrooms": ["1"],
"suite_type": "1 Bedroom",
"square_feet": ["594", "649"],
"deposit": ["$499"],
"price_range": ["$1059", "$1209"]
}, {
"available": "Available",
"bathrooms": ["1"],
"suite_type": "1 Bedroom + Den",
"square_feet": ["771"],
"deposit": ["$499"],
"price_range": ["$1169", "$1249"]
}, {
"available": "Available",
"bathrooms": ["1", "2"],
"suite_type": "2 Bedroom",
"square_feet": ["894", "970"],
"deposit": ["$499"],
"price_range": ["$1344", "$1494"]
}, {
"available": "Available",
"bathrooms": ["2"],
"deal": ["October FREE and $299 Security Deposit on 12 month leases "],
"suite_type": "2 Bedroom Bi-level",
"square_feet": ["894"],
"deposit": ["$499"],
"price_range": ["$1344", "$1394"]
}, {
"available": "Waiting List",
"bathrooms": ["1"],
"suite_type": "Bachelor",
"square_feet": ["540"],
"deposit": ["$499"],
"price_range": ["$1004", "$1054"]
}],
"address": "8830-85 St., Edmonton, Alberta, T6C 3C3",
"zip_code": "T6C 3C3"
}
And I am running a jq expression like:
'{phone_number, city, updated, name, address, zip_code, url, last_visited} + (.rooms[] | {suite_type, price_range_start: .price_range[0], price_range_end: .price_range[1]} + {available, square_foot_start:.square_feet[0], square_foot_end:.square_feet[1], deposit:.deposit[0], bathrooms:.bathrooms[0]})'
This gives me an ok output but repeats the same names because I just list the rooms array. I want to be able to set each item in the rooms array to something like room1, room2, room3 etc. But also to keep it in one entry, so for example with the sample here it ends up 5 entries because there is 5 rooms and name for instance gets repeated 5 times because the way I have it set now. I think I need to map the rooms to something but not sure how to do that.
Can someone advise on how to do this?
You can update the elements in the array whilst keeping the other elements as is like this:
'.rooms[] |= {suite_type, price_range_start: .price_range[0],
price_range_end: .price_range[1]} + {available,
square_foot_start:.square_feet[0], square_foot_end:.square_feet[1],
deposit:.deposit[0], bathrooms:.bathrooms[0]}'
Here is a solution which uses functions.
def common_columns:
"phone_number", "city", "updated", "name", "address", "zip_code", "url", "last_visited"
;
def common:
.phone_number, .city, .updated, .name, .address, .zip_code, .url, .last_visited
;
def room_columns(n):
range(n)
| (
"available_\(.)", "bathrooms_\(.)", "suite_type_\(.)",
"square_feet_start_\(.)", "square_feet_end_\(.)", "deposit_\(.)",
"price_range_start_\(.)", "price_range_end_\(.)"
)
;
def rooms(n):
. as $r
| range(n)
| $r.rooms[.]
| (
.available, .bathrooms[0], .suite_type,
.square_feet[0,1], .deposit[0], .price_range[0,1]
)
;
[ common_columns, room_columns(6) ]
, [ common, rooms(6) ]
| #csv
You can change the 6 to however many sets of room columns you need.