How to do arithmetic substraction of same identical key values between 2 json files and print it in output json file - json

I've 2 json files of with identical key fields on both the file. I would like to get your assistance to do arithmetic subtraction of values of same key field between 2 files and present in 3rd output file [ delta of two json files to output json file].
Also 1st and 2nd json files has n of array of indicies so we need to do this in loop to map the difference values in 3rd json output file.
Example:
1st Json file: file1.json
[
{
"name": "Rock",
"pri": 21,
"size": 502173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_current": 0,
"merges_total": 0,
"refresh_total": 0
},
{
"name": "Rock:config",
"pri": 21,
"size": 512173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_curr": 0,
"merges_tot": 0,
"refresh_tot": 0
}
]
2nd Json file: file1.json:
[
{
"name": "Rock",
"pri": 22,
"size": 602173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_current": 0,
"merges_total": 0,
"refresh_total": 0
},
{
"name": "Rock:config",
"pri": 31,
"size": 602173,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_curr": 0,
"merges_tot": 0,
"refresh_tot": 0
}
]
Output json file: file3.json should look like below.
[
{
"name": "Rock",
"pri": 1,
"size": 100000,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_current": 0,
"merges_total": 0,
"refresh_total": 0
},
{
"name": "Rock:config",
"pri": 10,
"size": 90000,
"gets": 0,
"searches": 40,
"search_time_ms": 25,
"fetches": 2,
"cache_mem_size": 0,
"cache_size": 0,
"cache_total": 2,
"hits": 0,
"misses": 2,
"index_total": 0,
"index_curr": 0,
"merges_tot": 0,
"refresh_tot": 0
}
]
please help me with the logic

This can be done as simple as u follow the following steps
Read the json object from 2 json files and save them as list of dictionaries
Loop through the list of dicts and perform your required manipulations
Save calculated output dicts to a new list
Write the resultant list to a new json file
the code is as follows,
import json
with open('file1.json') as f:
data1 = json.load(f)
with open('file2.json') as f:
data2 = json.load(f)
data = []
for i,j in zip(data1, data2):
x = {}
for m,n in zip(i.items(), j.items()):
# if m[0] != "name":
if m[0] == "pri" or m[0] == "size":
x[m[0]] = int(j[m[0]]) - int(i[m[0]])
else:
x[m[0]] = i[m[0]]
data.append(x)
with open('file3.json', 'w') as o:
json.dump(data, o)

Related

Regex to pick values from specific json key

My json string:
{
"computed_at": "2022-11-29T08:21:47.904741+00:00",
"data":
{
"2022-11-07":
{
"steps":
[
{
"count": 1853,
"avg_time": null,
"avg_time_from_start": null,
"session_event": "start",
"goal": "start",
"step_label": "Came to Corporate",
"overall_conv_ratio": 1,
"step_conv_ratio": 1
},
{
"count": 741,
"avg_time": 25451,
"avg_time_from_start": 25451,
"time_buckets_from_prev":
{
"lower": 0,
"higher": 0,
"buckets":
[
720,
2,
3,
4,
3,
3,
3,
1,
0,
2,
0,
0,
0,
0,
0
]
},
"time_buckets_from_start":
{
"lower": 0,
"higher": 0,
"buckets":
[
720,
2,
3,
4,
3,
3,
3,
1,
0,
2,
0,
0,
0,
0,
0
]
},
"event": "Viewed Collection Page",
"goal": "Viewed Collection Page",
"step_label": "Viewed Collection Page",
"overall_conv_ratio": 0.39989206691851054,
"step_conv_ratio": 0.39989206691851054
},
{
"count": 174,
"avg_time": 53538,
"avg_time_from_start": 110700,
"time_buckets_from_prev":
{
"lower": 0,
"higher": 0,
"buckets":
[
163,
2,
1,
3,
0,
2,
1,
2,
0,
0,
0,
0,
0,
0,
0
]
},
"time_buckets_from_start":
{
"lower": 0,
"higher": 0,
"buckets":
[
151,
4,
2,
5,
1,
4,
3,
3,
0,
1,
0,
0,
0,
0,
0
]
},
"event": "Product Viewed",
"goal": "Product Viewed",
"step_label": "Product Viewed",
"overall_conv_ratio": 0.09390178089584458,
"step_conv_ratio": 0.23481781376518218
}
],
"analysis":
{
"completion": 174,
"starting_amount": 1853,
"steps": 3,
"worst": 2
}
}
},
"meta":
{
"dates":
[
"2022-11-07"
],
"property_values":
[],
"min_sampling_factor": 1,
"group_by_metadata":
[]
},
"min_sampling_factor": 1
}
I want to extract the values for these particular keys (each of which has 3 instances in the above json string):
count
step_conv_ratio
What is the correct regex so that I will get 1853, 741, 174 for count; and 1, 0.39989206691851054, 0.23481781376518218 for step_conv_ratio?
Unmarshalling this to a Go struct is not ideal, since it has dynamic json field name, so I cannot use a static struct with static json tag to unmarshal. Hence I'm thinking of using regex.
Consider the comments about unmarshalling. Else the regex you are looking for is:
`"count": ([0-9]+)|"step_conv_ratio": ([0-9.]+)`
then the number will be in the second or the third element of the slice that contains the matches (e.g. after FindAllStringSubmatch()) depending on it's a count or a step_conv_ratio.

Need to import JSON data to Simple html file

Is there a way to import some data from json file into html file.
In need to import some of these data to a html file,
for example "Descrizione" and "Listino1" in a simple div.
Following is my json file sample:
[
{
"OP": "save",
"DB_NAME": "plu",
"ID": "005045",
"Barcode": "",
"CodVeloce": 0,
"CodPv": 0,
"FlagCondiviso": 1,
"CodTaccuino": 0,
"Descrizione": "BICC. VINO BIANCO",
"Famiglia": "006",
"ScortaMinima": 0,
"Posizione": 181,
"Reparto": 2,
"CodImmagini": 0,
"Listino1":4.00,
"Listino2":4.00,
"Listino3":0.00,
"Listino4":0.00,
"Stampante": 0,
"Flag": 1,
"Offerta": 0,
"Colore": 19,
"UnitMis": "",
"CodFornitore": 0,
"CodArtFornitore": "",
"BarcodeConfezione": "",
"PezziXConfezione": 0,
"ForzaLavoro": 0,
"PesoUnitario":0.00,
"NumConfezioni": 0,
"DescrizAggiuntiva": "",
"OffertaAggiuntiva": 0,
"PrezzoConfezione":0.00,
"ColoreTac": 0,
"Scala": 0,
"DtVar": "2020/02/03"
},
Any help.
Thanks in advance

Create a .csv File from JSON Data Using JQ

I thought that I knew enough about jq to be able to format .csv files the way I want, but there is always a trick that I have missed!.
My API download looks like this....
{
"status": "ok",
"meta": {
"count": 4
},
"data": {
"1019761328": {
"achievements": {
"medalCarius": 1,
"medalHalonen": 3,
"aimer": 6,
"invader": 13,
"armorPiercer": 18,
"medalMonolith": 2,
"medalEkins": 1,
"medalKay": 2,
"duelist": 409,
"newMeritPM2": 1,
"readyForBattleLT": 4,
"defender": 15,
"readyForBattleATSPG": 4,
"medalLeClerc": 2,
"demolition": 112,
"supporter": 13,
"steelwall": 107,
"medalLehvaslaiho": 28,
"medalAbrams": 2,
"readyForBattleSPG": 4,
"medalPoppel": 1,
"medalPascucci": 68,
"reliableComrade": 303,
"NY19A1": 1,
"NY19A2": 1,
"tankwomen": 1,
"luckyDevil": 10,
"NY18A3": 1,
"NY18A2": 1,
"mainGun": 28,
"NY18A1": 1,
"sinai": 5,
"firstMerit": 1,
"medalOrlik": 8,
"bonecrusher": 824,
"titleSniper": 41,
"warrior": 5,
"ironMan": 130,
"huntsman": 2,
"even": 35,
"medalKolobanov": 1,
"scout": 4,
"beasthunter": 5,
"kamikaze": 30,
"02YearsOfService": 1,
"tankExpert2": 1,
"tankExpert1": 1,
"readyForBattleMT": 4,
"tankExpert7": 1,
"tankExpert6": 1,
"sniper2": 10,
"arsonist": 106,
"charmed": 194,
"medalBillotte": 1,
"fighter": 147,
"medalLavrinenko": 2,
"impenetrable": 155,
"sturdy": 65,
"NY19A3": 1,
"medalKursk": 1,
"soldierOfFortune": 4,
"handOfDeath": 4,
"DdaymarathonMedal": 1,
"shootToKill": 3029,
"medalDumitru": 3,
"evileye": 8,
"medalKnispel": 1
},
"frags": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 29,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 595,
"geniusForWarMedal": 0,
"sinai": 523,
"pattonValley": 62
},
"max_series": {
"armorPiercer": 18,
"aimer": 6,
"titleSniper": 41,
"deathTrack": 0,
"invincible": 3,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 6,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 4
}
},
"1034967155": {
"achievements": {},
"frags": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 0,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 0,
"geniusForWarMedal": 0,
"sinai": 0,
"pattonValley": 0
},
"max_series": {
"armorPiercer": 0,
"aimer": 0,
"titleSniper": 0,
"deathTrack": 0,
"invincible": 0,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 0,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 0
}
}
}
}
My .csv output must contain an ID field, a Medal field and a field for # of Medals and look like this....
1019761328,"medalCarius",1
1019761328,"medalHalonen",3
1019761328,"aimer",6
...... etc. repeated for every ID
So far, these commands strip out the data I need....
jq -r '.data | to_entries[] | {id: .key, val: .value[]} '
resulting in....
{
"id": "1019761328",
"val": {
"medalCarius": 1,
"medalHalonen": 3,
"aimer": 6,
"invader": 13,
"armorPiercer": 18,
"medalMonolith": 2,
"medalEkins": 1,
"medalKay": 2,
"duelist": 409,
"newMeritPM2": 1,
"readyForBattleLT": 4,
"defender": 15,
"readyForBattleATSPG": 4,
"medalLeClerc": 2,
"demolition": 112,
"supporter": 13,
"steelwall": 107,
"medalLehvaslaiho": 28,
"medalAbrams": 2,
"readyForBattleSPG": 4,
"medalPoppel": 1,
"medalPascucci": 68,
"reliableComrade": 303,
"NY19A1": 1,
"NY19A2": 1,
"tankwomen": 1,
"luckyDevil": 10,
"NY18A3": 1,
"NY18A2": 1,
"mainGun": 28,
"NY18A1": 1,
"sinai": 5,
"firstMerit": 1,
"medalOrlik": 8,
"bonecrusher": 824,
"titleSniper": 41,
"warrior": 5,
"ironMan": 130,
"huntsman": 2,
"even": 35,
"medalKolobanov": 1,
"scout": 4,
"beasthunter": 5,
"kamikaze": 30,
"02YearsOfService": 1,
"tankExpert2": 1,
"tankExpert1": 1,
"readyForBattleMT": 4,
"tankExpert7": 1,
"tankExpert6": 1,
"sniper2": 10,
"arsonist": 106,
"charmed": 194,
"medalBillotte": 1,
"fighter": 147,
"medalLavrinenko": 2,
"impenetrable": 155,
"sturdy": 65,
"NY19A3": 1,
"medalKursk": 1,
"soldierOfFortune": 4,
"handOfDeath": 4,
"DdaymarathonMedal": 1,
"shootToKill": 3029,
"medalDumitru": 3,
"evileye": 8,
"medalKnispel": 1
}
}
{
"id": "1019761328",
"val": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 29,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 595,
"geniusForWarMedal": 0,
"sinai": 523,
"pattonValley": 62
}
}
{
"id": "1019761328",
"val": {
"armorPiercer": 18,
"aimer": 6,
"titleSniper": 41,
"deathTrack": 0,
"invincible": 3,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 6,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 4
}
}
{
"id": "1034967155",
"val": {}
}
{
"id": "1034967155",
"val": {
"crucialShotMedal": 0,
"prematureDetonationMedal": 0,
"sentinelMedal": 0,
"infiltratorMedal": 0,
"fightingReconnaissanceMedal": 0,
"fireAndSteelMedal": 0,
"rangerMedal": 0,
"reliableComrade": 0,
"pyromaniacMedal": 0,
"wolfAmongSheepMedal": 0,
"heavyFireMedal": 0,
"bruteForceMedal": 0,
"guerrillaMedal": 0,
"promisingFighterMedal": 0,
"beasthunter": 0,
"geniusForWarMedal": 0,
"sinai": 0,
"pattonValley": 0
}
}
{
"id": "1034967155",
"val": {
"armorPiercer": 0,
"aimer": 0,
"titleSniper": 0,
"deathTrack": 0,
"invincible": 0,
"victoryMarch": 0,
"EFC2016": 0,
"diehard": 0,
"WFC2014": 0,
"tacticalBreakthrough": 0,
"handOfDeath": 0
}
}
How do I now get this into the .csv format I need?
Any assistance would be greatly appreciated - thanks!
You can expand .value again with another application of to_entries[] and then generate csv output with string interpolation.
e.g.
.data | to_entries[] | {id: .key, val: (.value[] | to_entries[])} | "\(.id),\(.val.key),\(.val.value)"
Sample execution: with the above command in test.jq and your data in test.json and using head to show only the first ten lines:
$ jq -Mr -f test.jq test.json | head
1019761328,medalCarius,1
1019761328,medalHalonen,3
1019761328,aimer,6
1019761328,invader,13
1019761328,armorPiercer,18
1019761328,medalMonolith,2
1019761328,medalEkins,1
1019761328,medalKay,2
1019761328,duelist,409
1019761328,newMeritPM2,1
For your specific case a more robust way would be to use #csv instead of string interpolation. e.g.
.data | to_entries[] | {id: .key, val: (.value[] | to_entries[])} | [.id, .val.key, .val.value] | #csv
Sample execution
$ jq -Mr -f test.jq test.json | head
"1019761328","medalCarius",1
"1019761328","medalHalonen",3
"1019761328","aimer",6
"1019761328","invader",13
"1019761328","armorPiercer",18
"1019761328","medalMonolith",2
"1019761328","medalEkins",1
"1019761328","medalKay",2
"1019761328","duelist",409
"1019761328","newMeritPM2",1
If you know the id is a number and want the output to reflect that you can use tonumber as well:
.data | to_entries[] | {id: .key, val: (.value[] | to_entries[])} | [(.id|tonumber), .val.key, .val.value] | #csv
Sample execution
$ jq -Mr -f test.jq test.json | head
1019761328,"medalCarius",1
1019761328,"medalHalonen",3
1019761328,"aimer",6
1019761328,"invader",13
1019761328,"armorPiercer",18
1019761328,"medalMonolith",2
1019761328,"medalEkins",1
1019761328,"medalKay",2
1019761328,"duelist",409
1019761328,"newMeritPM2",1
in some way you need to apply a wide to long transformation.
You could complete your jq work unsing Miller (https://github.com/johnkerl/miller/issues), and applying this command to your json output
mlr --j2c unsparsify then reshape -r "val:" -o item,value then filter -S '$value!=""' then put -S '$item=gsub($item,"val:","")' input.json >output.csv
you will have
id,item,value
1019761328,medalCarius,1
1019761328,medalHalonen,3
1019761328,aimer,6
1019761328,invader,13
1019761328,armorPiercer,18
1019761328,medalMonolith,2
1019761328,medalEkins,1
1019761328,medalKay,2
1019761328,duelist,409
1019761328,newMeritPM2,1
1019761328,readyForBattleLT,4
1019761328,defender,15
1019761328,readyForBattleATSPG,4
1019761328,medalLeClerc,2
1019761328,demolition,112
1019761328,supporter,13
1019761328,steelwall,107
1019761328,medalLehvaslaiho,28
1019761328,medalAbrams,2
1019761328,readyForBattleSPG,4
1019761328,medalPoppel,1
1019761328,medalPascucci,68
1019761328,reliableComrade,303
1019761328,NY19A1,1
1019761328,NY19A2,1
1019761328,tankwomen,1
1019761328,luckyDevil,10
1019761328,NY18A3,1
1019761328,NY18A2,1
1019761328,mainGun,28
1019761328,NY18A1,1
1019761328,sinai,5
1019761328,firstMerit,1
1019761328,medalOrlik,8
1019761328,bonecrusher,824
1019761328,titleSniper,41
1019761328,warrior,5
1019761328,ironMan,130
1019761328,huntsman,2
1019761328,even,35
1019761328,medalKolobanov,1
1019761328,scout,4
1019761328,beasthunter,5
1019761328,kamikaze,30
1019761328,02YearsOfService,1
1019761328,tankExpert2,1
1019761328,tankExpert1,1
1019761328,readyForBattleMT,4
1019761328,tankExpert7,1
1019761328,tankExpert6,1
1019761328,sniper2,10
1019761328,arsonist,106
1019761328,charmed,194
1019761328,medalBillotte,1
1019761328,fighter,147
1019761328,medalLavrinenko,2
1019761328,impenetrable,155
1019761328,sturdy,65
1019761328,NY19A3,1
1019761328,medalKursk,1
1019761328,soldierOfFortune,4
1019761328,handOfDeath,4
1019761328,DdaymarathonMedal,1
1019761328,shootToKill,3029
1019761328,medalDumitru,3
1019761328,evileye,8
1019761328,medalKnispel,1
1019761328,reliableComrade,29
1019761328,sinai,523
1019761328,beasthunter,595
1019761328,crucialShotMedal,0
1019761328,prematureDetonationMedal,0
1019761328,sentinelMedal,0
1019761328,infiltratorMedal,0
1019761328,fightingReconnaissanceMedal,0
1019761328,fireAndSteelMedal,0
1019761328,rangerMedal,0
1019761328,pyromaniacMedal,0
1019761328,wolfAmongSheepMedal,0
1019761328,heavyFireMedal,0
1019761328,bruteForceMedal,0
1019761328,guerrillaMedal,0
1019761328,promisingFighterMedal,0
1019761328,geniusForWarMedal,0
1019761328,pattonValley,62
1019761328,aimer,6
1019761328,armorPiercer,18
1019761328,titleSniper,41
1019761328,handOfDeath,4
1019761328,deathTrack,0
1019761328,invincible,3
1019761328,victoryMarch,0
1019761328,EFC2016,0
1019761328,diehard,6
1019761328,WFC2014,0
1019761328,tacticalBreakthrough,0
1034967155,reliableComrade,0
1034967155,sinai,0
1034967155,beasthunter,0
1034967155,crucialShotMedal,0
1034967155,prematureDetonationMedal,0
1034967155,sentinelMedal,0
1034967155,infiltratorMedal,0
1034967155,fightingReconnaissanceMedal,0
1034967155,fireAndSteelMedal,0
1034967155,rangerMedal,0
1034967155,pyromaniacMedal,0
1034967155,wolfAmongSheepMedal,0
1034967155,heavyFireMedal,0
1034967155,bruteForceMedal,0
1034967155,guerrillaMedal,0
1034967155,promisingFighterMedal,0
1034967155,geniusForWarMedal,0
1034967155,pattonValley,0
1034967155,aimer,0
1034967155,armorPiercer,0
1034967155,titleSniper,0
1034967155,handOfDeath,0
1034967155,deathTrack,0
1034967155,invincible,0
1034967155,victoryMarch,0
1034967155,EFC2016,0
1034967155,diehard,0
1034967155,WFC2014,0
1034967155,tacticalBreakthrough,0

Convert from ThreeJS geometry format 3 to 4: dealing with faces

I am having some problems with migration from ThreeJS geometry format 3 to 4. More specifically, i would like to manually create a surface in model.json file, but i don't get it to work.
in geometry format 3, the following code creates a single surface:
{
"faces": [1, 0, 1, 2, 3],
"metadata": {
"faces": 1
},
"vertices": [0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0]
}
Can some-one help me how to convert this to format 4?
The only example on geometry format 4 i could find was this one: https://github.com/mrdoob/three.js/wiki/JSON-Geometry-format-4
This is the equivalent code in json-geometry format 4:
{
"vertices": [0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0],
"normals": [],
"uvs": [],
"faces": [ 1, 0, 1, 2, 3]
}

Getting valurs froM JSON objects that have the same object string name

I'm getting my JSON object from the RIOT games API. Here is part of the JSON I get back:
{
"modifyDate": 1431043986000,
"champions": [
{
"id": 110,
"stats": {
"totalDeathsPerSession": 9,
"totalSessionsPlayed": 1,
"totalDamageTaken": 16507,
"totalQuadraKills": 0,
"totalTripleKills": 0,
"totalMinionKills": 164,
"maxChampionsKilled": 2,
"totalDoubleKills": 0,
"totalPhysicalDamageDealt": 101747,
"totalChampionKills": 2,
"totalAssists": 2,
"mostChampionKillsPerSession": 2,
"totalDamageDealt": 105995,
"totalFirstBlood": 0,
"totalSessionsLost": 1,
"totalSessionsWon": 0,
"totalMagicDamageDealt": 4248,
"totalGoldEarned": 7932,
"totalPentaKills": 0,
"totalTurretsKilled": 0,
"mostSpellsCast": 0,
"maxNumDeaths": 9,
"totalUnrealKills": 0
}
},
{
"id": 113,
"stats": {
"totalDeathsPerSession": 6,
"totalSessionsPlayed": 1,
"totalDamageTaken": 39226,
"totalQuadraKills": 0,
"totalTripleKills": 0,
"totalMinionKills": 75,
"maxChampionsKilled": 5,
"totalDoubleKills": 1,
"totalPhysicalDamageDealt": 28711,
"totalChampionKills": 5,
"totalAssists": 8,
"mostChampionKillsPerSession": 5,
"totalDamageDealt": 177132,
"totalFirstBlood": 0,
"totalSessionsLost": 1,
"totalSessionsWon": 0,
"totalMagicDamageDealt": 120299,
"totalGoldEarned": 12544,
"totalPentaKills": 0,
"totalTurretsKilled": 1,
"mostSpellsCast": 0,
"maxNumDeaths": 6,
"totalUnrealKills": 0
}
},
and so on for all of the champions in the game (there are around 150). If I wanted to calculate the total win/loss ratio or percent, I would have to find the total of "totalSessionsLost" and "totalSessionsWon". How would I go about totaling all of the values for this?
Thanks
var total_win = 0,
total_lost = 0,
champions = yourjsonobj.champions;
for (var i = 0; i < champions.length; i++) {
total_win += champions[i].totalSessionsWon;
total_lost += champions[i].totalSessionsLost;
}