I want to remove 'Software 3' in the array. I'm quite new with json data and I do not know what is the correct way to do it. I have tried the unset method but its not working. Can anyone show me the example. I already search the solution but most of it not using multiple array.
json data:
"system_info": {
"hardware": {
"model": "PowerEdge R710",
"serialno": "FG6MC2S",
"warranty": {
"warranty_start_date": "2022-03-14",
"warranty_end_date": "2025-03-14"
}
},
"operating_env": {
"os": "PowerEdge R710",
"os_version": "FG6MC2S"
},
"software_installed": [
{
"name": "Software 1",
"version": "4.5"
},
{
"name": "Software 2",
"version": "5.5"
},
{
"name": "Software 3",
"version": "5.5"
}
]},
Using javascript
const data = {
system_info: {
hardware: {
model: 'PowerEdge R710',
serialno: 'FG6MC2S',
warranty: {
warranty_start_date: '2022-03-14',
warranty_end_date: '2025-03-14',
},
},
operating_env: {
os: 'PowerEdge R710',
os_version: 'FG6MC2S',
},
software_installed: [
{
name: 'Software 1',
version: '4.5',
},
{
name: 'Software 2',
version: '5.5',
},
{
name: 'Software 3',
version: '5.5',
},
],
},
};
const { system_info: { hardware, operating_env, software_installed } } = data;
const newData = {
system_info: {
hardware,
operating_env,
software_installed: software_installed.filter(s => s.name !== 'Software 3')
}
}
console.log(newData);
Using python. I will assume that this data lives in data.json
remove_script.py
import json
# Opening JSON file
with open('data.json') as json_file:
data = json.load(json_file)
# Remove software 3
data['system_info'].update(
{"software_installed": data['system_info']['software_installed'][:2]})
print(data)
# write to another file
with open("output.json", "w") as write_file:
json.dump(data, write_file, indent=4)
printed output
>>> {'system_info': {'hardware': {'model': 'PowerEdge R710', 'serialno': 'FG6MC2S', 'warranty': {'warranty_start_date': '2022-03-14', 'warranty_end_date': '2025-03-14'}}, 'operating_env': {'os': 'PowerEdge R710', 'os_version': 'FG6MC2S'}, 'software_installed': [{'name': 'Software 1', 'version': '4.5'}, {'name': 'Software 2', 'version': '5.5'}]}}
output.json
{
"system_info": {
"hardware": {
"model": "PowerEdge R710",
"serialno": "FG6MC2S",
"warranty": {
"warranty_start_date": "2022-03-14",
"warranty_end_date": "2025-03-14"
}
},
"operating_env": {
"os": "PowerEdge R710",
"os_version": "FG6MC2S"
},
"software_installed": [
{
"name": "Software 1",
"version": "4.5"
},
{
"name": "Software 2",
"version": "5.5"
}
]
}
}
Related
I have an Alexa project for smart home shades that include two range controllers, a brightness controller, and a toggle controller on each endpoint.
The two range controllers, toggle controller, and brightness controller all have different instances and friendlyNames.
When issuing commands to Alexa, anything containing a percentage is defaulting to the brightness controller regardless of how the command is phrased. If I fully remove the brightness controller and attempt to issue a rotation command (range controller), depending on the device, I get incredibly inconsistent results stating it doesn't know how to set the setting. Some devices will work around 90% at first and will then suddenly fail consistently. Other devices wont work at all. No device is consistently working.
If I reduce down to any one of the capabilities, it works nearly 100% of the time.
Has anyone else experienced this behavior and is there any solution?
Capability code:
export const ROTATE_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.RangeController",
version: "3",
instance: "Blind.Rotate",
properties: {
supported: [{ name: "rangeValue" }],
proactivelyReported: false,
retrievable: true,
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Vane",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Tilt",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Angle",
locale: "en-US"
}
}
]
},
configuration: {
supportedRange: {
minimumValue: 0,
maximumValue: 100,
precision: 1,
},
unitOfMeasure: "Alexa.Unit.Percent"
}
}
export const BRIGHTNESS_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.BrightnessController",
version: "3",
instance: "Blind.Brightness",
properties: {
supported: [
{
name: "brightness"
}
],
proactivelyReported: false,
retrievable: true
}
}
export const BRIGHTNESS_TOGGLE = {
type: "AlexaInterface",
interface: "Alexa.ToggleController",
instance: "Blind.Light",
version: "3",
properties: {
supported: [
{
name: "toggleState"
}
],
proactivelyReported: false,
retrievable: true,
nonControllable: false
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Shade Light",
locale: "en-US"
}
},
{
"#type": "text",
value: {
text: "Light",
locale: "en-US"
}
}
]
}
}
export const MAIN_CAPABILITY = {
type: "AlexaInterface",
interface: "Alexa.RangeController",
instance: "Blind.Lift",
version: "3",
properties: {
supported: [{
name: "rangeValue",
},],
proactivelyReported: false,
retrievable: true,
},
capabilityResources: {
friendlyNames: [
{
"#type": "text",
value: {
text: "Shade",
locale: "en-US"
}
}
],
},
configuration: {
supportedRange: {
minimumValue: 0,
maximumValue: 100,
precision: 1,
},
unitOfMeasure: "Alexa.Unit.Percent",
},
semantics: {
actionMappings: [{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Close"],
directive: {
name: "SetRangeValue",
payload: {
rangeValue: 0,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Open"],
directive: {
name: "SetRangeValue",
payload: {
rangeValue: 100,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Lower"],
directive: {
name: "AdjustRangeValue",
payload: {
rangeValueDelta: -10,
rangeValueDeltaDefault: false,
},
},
},
{
"#type": "ActionsToDirective",
actions: ["Alexa.Actions.Raise"],
directive: {
name: "AdjustRangeValue",
payload: {
rangeValueDelta: 10,
rangeValueDeltaDefault: false,
},
},
},
],
stateMappings: [{
"#type": "StatesToValue",
states: ["Alexa.States.Closed"],
value: 0,
},
{
"#type": "StatesToRange",
states: ["Alexa.States.Open"],
range: {
minimumValue: 1,
maximumValue: 100,
},
},
],
},
}
Given a collection of documents similar to the following document
{
"_id": {
"$oid": "60582f08bf1d636f4b762ebc"
}
"experience": [{
"title": "Senior Customer Success Account Manager",
"company": "Microsoft",
"tenure": 8
}, {
"title": "Senior Service Delivery Manager",
"company": "Microsoft",
"tenure": 34
}],
"company3": "Oracle",
"tenure3": 10,
"title3": "Senior Customer Success Manager - EMEA |Oracle Marketing Cloud"
}
How would I write an updateMany or other shell command to move company3, tenure3 and title3 inside the experience array as a new object {company: <company3 value>, title: <title3 value>, tenure: <tenure3 value>} ?
Seems like you're looking for this aggregation update:
db.collection.update({},
[
{
$set: {
experience: {
$concatArrays: [
"$experience",
[
{
company: "$company3",
title: "$title3",
tenure: "$tenure3"
}
]
]
}
}
},
{
$unset: "company3"
},
{
$unset: "tenure3"
},
{
$unset: "title3"
}
],
{
multi: true
})
Playground: https://mongoplayground.net/p/xoEveE0rdBN
{
"a": [
[
{
"_id": "57e55b64016c3551c025abc1",
"title": "Main Campus"
},
{
"_id": "5810e2e27064497f74ad4874",
"title": "Ahm Campus"
},
{
"_id": "5d5d2633a1d0680620ac3cce",
"title": "Baroda"
},
{
"_id": "5d5d3af3a1d0680620ac3ef8",
"title": "India"
}
],
[
{
"_id": "57e55b64016c3551c025abc1",
"title": "Main Campus"
},
{
"_id": "5810e2e27064497f74ad4874",
"title": "Ahm Campus"
},
{
"_id": "5d5d2633a1d0680620ac3cce",
"title": "Baroda"
},
{
"_id": "5d5d3af3a1d0680620ac3ef8",
"title": "India"
}
]
]
}
How to create the schema in the realm(React native) for this type of JSON object. I tried all possible ways but did not found any specific solution. Basically, it is a nested array where the second array does not have any specific key(I tried with key it works fine but I want to do it without adding key).
You can use something like:
const ParentSchema = {
name: "parent",
properties: {
key: "string",
values: "Value[]"
}
};
const ValueSchema = {
name: "Value",
embedded: true,
properties: {
_id: "string",
title: "string"
}
};
You can insert objects like:
realm.write(() => {
realm.create("Parent", { key: "a", values: [
{ _id: "57e55b64016c3551c025abc1", title: "Main Campus" },
{ _id: "5810e2e27064497f74ad4874", title: "Ahm Campus" }
]
});
});
Documentation: https://docs.mongodb.com/realm/node/data-model
As of now there is no way to insert direct value in Realm database without key so for now we need to modify data and then we can store in following schema.
const ParentSchema = {
name: "parent",
properties: {
a: "level[]"
}
};
const level = {
name: 'level',
properties: {
level: 'sites[]'
}
}
const sites = {
name: 'sites',
properties: {
sites: 'site[]'
}
}
const site = {
name: 'site',
properties: {
title: 'string?',
_id: 'string?',
version: 'int?',
}
}
Data modification need to done like following.
var a = {
level: []
}
data.a.map((Site, index) => {
const sites = []
Site.map((s) => { sites.push(s)})
a.level.push({sites})
})
I want to build a combination chart with a column chart with multiple series and a line chart. Problem is that I am getting High charts data from nested JSON response. For that I initialized array and that array is giving in series in plotoptions highcharts as you can see in the below code.
My code is like this:
var crime_data=[];
for(var i=0;i<result.themes.length;i++){
var crime={};
var test2 = result.themes[i];
var test = test2[Object.keys(test2)];
crime.name = Object.keys(result.themes[i]);
crime.data = [];
for(var k=0;k<test.yearTheme.length;k++){
var test3=test.yearTheme[k];
var test5=test3.individualValueVariable;
for(var j=0;j<test5.length;j++){
crime.data.push(test5[j].count);
};
};
crime_data.push(crime);
};
var crimeChart = new Highcharts.Chart({
chart: {
renderTo: 'container1',
type:'column'
},
title: {
text: 'Crime'
},
xAxis: {
categories: month,
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Count'
}
},
credits: {
enabled: false
},
tooltip: {
shared: true,
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0,
depth: 25,
allowPointSelect: true,
cursor: 'pointer',
point: {
},
}
},
series: crime_data
});
This is Column chart I am getting when i write chart type column.
This is my Line Chart I am getting when i changed type column to spline in chart in highcharts.
And this is my JSON data(Highcharts data):
{
"boundaries": {
"boundary": [
{
"boundaryId": "55083021003",
"boundaryType": "USA_CITY",
"boundaryRef": "C1"
}
]
},
"themes": [
{
"AssaultCrimeTheme": {
"boundaryRef": "C1",
"individualValueVariable": [
{
"name": "2013 Assault Crime",
"description": "Assault Crime for 2013",
"count": 18901
},
{
"name": "2014 Assault Crime",
"description": "Assault Crime for 2014",
"count": 17707
}
]
}
},
{
"BurglaryCrimeTheme": {
"boundaryRef": "C1",
"individualValueVariable": [
{
"name": "2013 Burglary Crime",
"description": "Burglary Crime for 2013",
"count": 17743
},
{
"name": "2014 Burglary Crime",
"description": "Burglary Crime for 2014",
"count": 14242
}
]
}
}
]
}
I want to combine both of them in the same container with same data.The problem is in how to tell highcharts multiple series should be represented with line and with column type with same data.For this when i write series:[{ data: crime_data ,type: spline }] instead of series:crime_data In that case I am not getting Highcharts data. Can anyone Please help me how should i do this.Please suggest me.
Pass your data, like below format. add type of chart in each data series;
Here i replaced type value but with same data.
[{
type: 'line',
name: 'AssaultCrimeTheme',
data: [3, 2, 1, 3, 4]
}, {
type: 'line',
name: 'BurglaryCrimeTheme',
data: [2, 3, 5, 7, 6]
}, {
type: 'column',
name: 'AssaultCrimeTheme',
data: [3, 2, 1, 3, 4]
}, {
type: 'column',
name: 'BurglaryCrimeTheme',
data: [2, 3, 5, 7, 6]
},]
Here is fiddle for more details.
Here is a complete example using your data.
const json = {
"boundaries": {
"boundary": [{
"boundaryId": "55083021003",
"boundaryType": "USA_CITY",
"boundaryRef": "C1"
}]
},
"themes": [{
"AssaultCrimeTheme": {
"boundaryRef": "C1",
"individualValueVariable": [{
"name": "2013 Assault Crime",
"description": "Assault Crime for 2013",
"count": 18901
}, {
"name": "2014 Assault Crime",
"description": "Assault Crime for 2014",
"count": 17707
}]
}
}, {
"BurglaryCrimeTheme": {
"boundaryRef": "C1",
"individualValueVariable": [{
"name": "2013 Burglary Crime",
"description": "Burglary Crime for 2013",
"count": 17743
}, {
"name": "2014 Burglary Crime",
"description": "Burglary Crime for 2014",
"count": 14242
}]
}
}]
}
// Create categories object in order filter duplicates
const cats = {}
const series = json.themes.map((o) => {
const key = Object.keys(o)[0]
return {
name: key,
data: o[key].individualValueVariable.map((o) => {
cats[o.name] = 1
return { category: o.name, y: o.count }
})
}
})
// Convert categories object to array
const categories = Object.keys(cats)
// Chart options
const options = {
chart: {type: 'column'},
xAxis: {categories: categories},
series: series
}
// Create chart
const chart = Highcharts.chart('container', options)
console.log(series, categories)
Live example: https://jsfiddle.net/Lo323gq3/
Output below:
How to call the data from json in angularjs form without using backend. i have written this code and here m unable to find a way in last to get data from the json file. someone please help me to move forward from here.
code
$scope.count = $scope.newPreAuth.length;
};
//Delete newPreAuth - Using AngularJS splice to remove the preAuth row from the newPreAuth list
//All the Update newPreAuth to update the locally stored newPreAuth List
//Update the Count
$scope.deletenewPreAuth = function (preAuth) {
$scope.newPreAuth.splice($scope.newPreAuth.indexOf(preAuth), 1);
getLocalStorage.updatenewPreAuth($scope.newPreAuth);
$scope.count = $scope.newPreAuth.length;
};
}]);
//Create the Storage Service Module
//Create getLocalStorage service to access UpdateEmployees and getEmployees method
var storageService = angular.module('storageService', []);
storageService.factory('getLocalStorage', function () {
var newPreAuthList = {};
return {
list: newPreAuthList,
updatenewPreAuth: function (newPreAuthArr) {
if (window.localStorage && newPreAuthArr) {
//Local Storage to add Data
localStorage.setItem("newPreAuth", angular.toJson(newPreAuthArr));
}
newPreAuthList = newPreAuthArr;
},
getnewPreAuth: function () {
//Get data from Local Storage
newPreAuthList = angular.fromJson(localStorage.getItem("newPreAuth"));
return newPreAuthList ? newPreAuthList : [];
}
};
});
Json Code
PreAuth:
======================
URL:http://dev.xxx.com:8080/xxx/preAuth
TYPE:POST
X-Auth-Token t3Z10HGEiYFdzq9lGtr18ycdeAAXmWBEI64rQAJcAte6Ka8Tz96IAhuXHSgpiKufsd
{
"preAuth": {
"claimbId": "newPreAuth",
"claimbStatus": "new",
"patientInfo": {
"patientName": "name",
"gender": "Male",
"dob": 950639400000,
"age": 21,
"contactNumber": 9987654356,
"tpaMemberId": 950639400121,
"policyNumber": "ABC12615627",
"corporateName": "ABC",
"EmployeeId": "XYZ10232",
"otherInsurance": {
"isOtherInsurance": true,
"playerName": "xyx",
"details": "sdfdsafdsfdsf"
},
"familyPhysician": {
"isFamilyPhysician": true,
"physicianName": "fsdf"'c
"physicianContactNumber": 7878748728,
"address": {
"address1": "Hosa road",
"address2": "Basapura",
"city": "Bangalore",
"state": "Karnataka",
"country": "India",
"pincode": "560100"
}
},
"isFamilyPhysician": false,
"address": {
"address1": "Hosa road",
"address2": "Basapura",
"city": "Bangalore",
"state": "Karnataka",
"country": "India",
"pincode": "560100"
}
},
"medicalInfo": {
"illnessType": "cancer",
"clinicalFinding": "description",
"ailmentDuration": "2 months",
"ailmentHistory": "description",
"illnessCause": "alcohol",
"provisionalDiagnosis": [
{
"diagnosisName": "abc",
"diagnosisICDCode": "121423"
},
{
"diagnosisName": "xyz",
"diagnosisICDCode": "434543"
}
],
"differentialDiagnosis": [
{
"diagnosisName": "afasdbc",
"diagnosisICDCode": "12431423"
},
{
"diagnosisName": "fdxyz",
"diagnosisICDCode": "434sdf543"
}
],
"clinicalObservations": {
"BP": "120/80",
"CVS": "126",
"P.A.": "abc",
"R.S.": "aa",
"CNS": "dd",
"others": "others"
},
"maternityDetails": {
"maternityType": "G",
"L.M.P.": 950639400000,
"E.D.D.": 950639400000
},
"accidentDetails": {
"accidentCause": "xyz",
"accidentDate": 950639400000,
"isPoliceComplaint": true,
"firNumber": "asfsafds"
},
"pastIllness": [
{
"pastIllnessType": "Diabetes",
"isPresent": true,
"NoOfMonth": 2,
"NoOfYear": 5,
"illnessSince": 950639400000
},
{
"pastIllnessType": "Hypertension",
"isPresent": true,
"NoOfMonth": 2,
"NoOfYear": 5,
"illnessSince": 950639400000
},
{
"pastIllnessType": "Other",
"isPresent": false,
"NoOfMonth": 2,
"NoOfYear": 5,
"illnessSince": 950639400000
}
]
},
"treatmentInfo": {},
"billingInfo": {},
"documents": [
{
"documentId": 12345,
"documentMetadata": {
"documentName": "discharge summary",
"date": 950639400000,
"version": "1.1",
"viewedStatus": false,
"link": "link to view/download document"
}
},
{
"documentId": 12346,
"documentMetadata": {
"documentName": "medical summary",
"date": 950639400000,
"version": "1.0",
"viewedStatus": true,
"link": "link to view/download document"
}
}
]
}
}
I created sample ,it worked this way
// Code goes here
var app = angular.module('app',[]);
app.controller('sample', function($scope,$http){
$scope.name = "advaitha";
$http.get('test.json').then(function(data){
console.log(data.data);
});
})
here is the plunker example
using HTML5 localStorage would require you to serialize and deserialize your objects before using or saving them.
For example:
var myObj = {
firstname: "kisun",
lastname: "rajot",
website: "https://www.kisun.com"
}
//if you wanted to save into localStorage, serialize it
window.localStorage.set("empData", JSON.stringify(myObj));
//unserialize to get object
var myObj = JSON.parse(window.localStorage.get("empData"));
Created a plunker based on your code am able save and retrieve the json data with your code. Please check here