Mapping JSON key-value directly into a Map (object.Entries does not work)

Advertisements I have a simple object structure like this: { "Anna": [ "ItemA", "ItemB", ] } and I need to create a Map out of it. Using new Map(Object.entries(json)) results into the following, where the key is 0 instead of the name "Anna", which I would need: { "key": "0", "value": { "Anna": [ "ItemA",… Read More Mapping JSON key-value directly into a Map (object.Entries does not work)

How to convert row to column Json object

Advertisements i have bellow json format const datalist = [{"Week":"01","Apple":8,"Orange":1}, {"Week":"02","Orange":9,"Apple":1}, {"Week":"03","Apple":10,"Orange":0}]; i want to convert into bellow format const datalist = [{"Food":"Apple","Week 1":8,"Week 2":1, "Week 3": 10, "Total" : 19}, {"Food":"Orange","Week 1":0,"Week 2":9, "Week 3": 0, "Total" :10 }]; i used bellow logic but im not able to get the correct result also the… Read More How to convert row to column Json object

converting json date format from string to datetime format in python

Advertisements currently im trying to convert an incoming JSON data with a time stamp in string format to a datetime in python. the following data of the string is this: 2022-12-30T16:27:56.9871548+08:00 I tried to convert this string to datetime using strptime and when i tried doing this below: from datetime import datetime date = datetime.strptime(‘2022-12-30T16:27:56.9871548+08:00’,… Read More converting json date format from string to datetime format in python

Python Script to load JSON file and save values to variables

Advertisements Hello I have this code to load a JSON file and I want to pass values to variables: with open(‘C:/files/response.json’) as json_file: data = json.load(json_file) for item in data: if ‘XMLRESPONSE’ in item: property_values.append(item[‘ITEM’][‘TOTALQTY’]) testvalue = str(property_values[0]) print (testvalue) But for that instance only I have the error: “TypeError: string indices must be integers”… Read More Python Script to load JSON file and save values to variables

How can I call a JSON value using Python?

Advertisements I have a JSON file with some data: { "item": { "userid":"", "kissed": { "kisseduser0":"", "kisseduser0times":"", "kisseduser1":"", "kisseduser1times":"", "kisseduser2":"", "kisseduser2times":"" } }, "item1": { "userid":"", "kissed": { "kisseduser0":"", "kisseduser0times":"", "kisseduser1":"", "kisseduser1times":"", "kisseduser2":"", "kisseduser2times":"" } } } I’m trying to call "userid" value (In the future I’ll use kisseduser) using python, like that: with open(‘dictionary.json’)… Read More How can I call a JSON value using Python?