Need to import JSON data to Simple html file - html

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

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.

Mapping an array in inside another array and display into a table in more than one entry

I have data that include the result of student each in an array but also with different subject basing on subject that they undertake. I want to map through them to be able to insert it into a table with respect to the subject and they mark which has to be matching.
This is my API result
{
"status": 200,
"message": "Successfully retrieve",
"data": [
{
"studentNumber": "22001",
"gender": "M",
"result": [
{
"moduleCode": "CHE1163",
"continousAssesment": 42,
"Exam": 6,
"workMaxContinousAssement": 55,
"actualContinousAssesment": 38.18181818181819,
"actualMaxContinousAssesment": 50,
"maxExam": 50,
"total": 44.18181818181819,
"studentNumber": "22001",
"moduleCredit": 10
},
{
"moduleCode": "MEE1162",
"continousAssesment": 10,
"Exam": 40,
"workMaxContinousAssement": 45,
"actualContinousAssesment": 11.11111111111111,
"actualMaxContinousAssesment": 50,
"maxExam": 50,
"total": 51.111111111111114,
"studentNumber": "22001",
"moduleCredit": 15
}
]
},
{
"studentNumber": "1111",
"gender": "M",
"result": [
{
"moduleCode": "CHE1163",
"continousAssesment": 0,
"Exam": 23,
"workMaxContinousAssement": 0,
"actualContinousAssesment": 0,
"actualMaxContinousAssesment": 50,
"maxExam": 50,
"total": 23,
"studentNumber": "1111",
"moduleCredit": 10
},
{
"moduleCode": "MEE1162",
"continousAssesment": 12,
"Exam": 20,
"workMaxContinousAssement": 45,
"actualContinousAssesment": 13.333333333333334,
"actualMaxContinousAssesment": 50,
"maxExam": 50,
"total": 33.333333333333336,
"studentNumber": "1111",
"moduleCredit": 15
}
]
},
{
"studentNumber": "667",
"gender": "F",
"result": [
{
"moduleCode": "CHE1163",
"continousAssesment": 0,
"Exam": 3,
"workMaxContinousAssement": 0,
"actualContinousAssesment": 0,
"actualMaxContinousAssesment": 50,
"maxExam": 50,
"total": 3,
"studentNumber": "667",
"moduleCredit": 10
},
{
"moduleCode": "MEE1162",
"continousAssesment": 17,
"Exam": 40,
"workMaxContinousAssement": 45,
"actualContinousAssesment": 18.88888888888889,
"actualMaxContinousAssesment": 50,
"maxExam": 50,
"total": 58.888888888888886,
"studentNumber": "667",
"moduleCredit": 15
}
]
}
]
}
the result I should be expecting is something like this
I have tried to map from to but it showing nothing when I replace the value as variable
this is the part of the table code
overallResult.map((item) => {
return (
<>
<tr>
<td></td>
<td>{item.studentNumber}</td>
<td className="font-medium">{item.gender}</td>
<td>44.18181818181819</td>
<td>51.111111111111114</td>
<td>45</td>
</tr>
</>
)
}
This should be mapping and then insert the actual value into the for the map which is corresponding to the student as seen in table picture
I updated your sandbox link.
Instead of hard coded data, now your table is populated with the data from overallResult object.
It is not perfect, but at least you can see how to loop through a data and display on the screen.
https://codesandbox.io/s/angry-bardeen-brkzf5?file=/src/App.js

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

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)

Wrong information in metadata/properties for IFC file

When calling
https://developer.api.autodesk.com/modelderivative/v2/designdata/{urn}/metadata/{guid}/properties
over IFC file, the response contains wrong information. Instead of returning the property name, it returns it's type. Example
"properties": {
"Item": {
"LcOaNode:LcOaNodeGuid": "c13f6c25-d776-584a-8b84-c7132760a018",
"LcOaNode:LcOaNodeHidden": 0,
"LcOaNode:LcOaNodeIcon": "File",
"LcOaNode:LcOaNodeMaterial": "",
"LcOaNode:LcOaNodeRequired": 0,
"LcOaNode:LcOaSceneBaseClassUserName": "File",
"LcOaNode:LcOaSceneBaseUserName": "3d337589-4cea-4301-a236-4b39c1e15ac9.Ifc",
"LcOaNode:LcOaUnit": "Millimeters"
},
"Material": {
"LcOaExMaterial:LcOaMaterialAmbient0": 1,
"LcOaExMaterial:LcOaMaterialAmbient1": 1,
"LcOaExMaterial:LcOaMaterialAmbient2": 1,
"LcOaExMaterial:LcOaMaterialDiffuse0": 1,
"LcOaExMaterial:LcOaMaterialDiffuse1": 1,
"LcOaExMaterial:LcOaMaterialDiffuse2": 1,
"LcOaExMaterial:LcOaMaterialEmissive0": 0,
"LcOaExMaterial:LcOaMaterialEmissive1": 0,
"LcOaExMaterial:LcOaMaterialEmissive2": 0,
"LcOaExMaterial:LcOaMaterialShininess": 0.00001,
"LcOaExMaterial:LcOaMaterialSpecular0": 0,
"LcOaExMaterial:LcOaMaterialSpecular1": 0,
"LcOaExMaterial:LcOaMaterialSpecular2": 0,
"LcOaExMaterial:LcOaMaterialTransparency": 0
}, ....
Where "LcOaExMaterial:LcOaMaterialAmbient0" is returned for example, it should be the property's name.
IFC files are extracted via Navisworks and this is an expected behaviour. For a given property, you can use the displayName (if available).

Mongo $and query returning no results

How do I approach writing a query to return all the records matching both match.id and player.name for the following collection?
{
"match": {
"id": 1,
"event": {
"timestamp": "2015-06-03 15:02:22",
"event": "round_stats",
"round": 1,
"player": {
"name": "Jim",
"userId": 45,
"uniqueId": "BOT",
"team": 2
},
"shots": 0,
"hits": 0,
"kills": 0,
"headshots": 0,
"tks": 0,
"damage": 0,
"assists": 0,
"assists_tk": 0,
"deaths": 0,
"head": 0,
"chest": 0,
"stomach": 0,
"leftArm": 0,
"rightArm": 0,
"leftLeg": 0,
"rightLeg": 0,
"generic": 0
}
}
}
I've attempted it with both the following query statements, but had no luck -- they both return no results:
db.warmod_events.find( { $and: [ { "match.id": 1}, { "player.name": 'Jim' } ] } )
db.warmod_events.find( { $and: [ { "match.id": 1}, { "event": { "player.name": "Jim" } } ] } )
I'm pretty new to Mongo and any guidance and explanation would help a bunch -- truthfully I've chosen to use Mongo for this project as the data I am working with is already presented in this form (the JSON) and, due to that, it seemed like a good opportunity to use and learn Mongo.
I am referring to the documentation on the Mongo site currently.
Thanks all
Try the following query:
db.warmod_events.find({ "match.id": 1, "match.event.player.name": 'Jim' })
which will match documents where the match id is the same as the embedded document player name.