Sorting multiple sections of a json - json

I am attempting to sort a .json. The json should be sorted first by "Name" and then a sort of everything in "Products". The sort would need to be done via PowerShell.
I have attempted using a derivative of powershell sort json by value with Sort-Object but with no success.
$json = Get-Content '.\.vscode\driverDetails.json' | ConvertFrom-Json
$json.Name = $json.Name | Sort-Object Name
$json.Products = $json.Products | Sort-Object Products
$json | ConvertTo-Json
The json itself should be sorted by "Name"
Everything under "Products" is sorted.
Example below
Original Json:
[
{
"Name": "HPE Smart Array P824i-p MR 64-bit controller driver for Microsoft Windows 2016 edition.",
"cpFile": "cp034411",
"version": "6.714.18.0",
"OS": "Microsoft Windows Server 2016",
"Products": [
"HPE ProLiant DL380 Gen10 Server",
"HPE ProLiant DL560 Gen10 Server",
"HPE ProLiant DL385 Gen10 Server\n",
"HPE ProLiant ML350 Gen10 Server",
"HPE ProLiant DL360 Gen10 Server",
"HPE ProLiant DL580 Gen10 Server"
],
"Description": "This driver, MegaSAS2, provides Windows 64-bit support for HPE Smart Array P824i-p MR 64-bit controller",
"Category": "Driver - Storage Controller"
},
{
"Name": "HPE H2xx SAS/SATA Host Bus Adapter Driver for 64-bit Microsoft Windows Server 2016 Editions",
"cpFile": "cp037731",
"version": "2.68.64.2",
"OS": "Microsoft Windows Server 2016",
"Products": [
"HPE ProLiant DL360 Gen9 Server",
"HPE ProLiant DL380 Gen9 Server",
"HPE ProLiant DL560 Gen9 Server",
"HPE ProLiant ML350 Gen9 Server"
],
"Description": "This driver, LSI_SAS2, provides Windows Server 2016 support for HPE H2xx SAS/SATA Host Bus Adapter. ",
"Category": "Driver - Storage Controller"
}
]
Sorted Json:
[
{
"Name": "HPE H2xx SAS/SATA Host Bus Adapter Driver for 64-bit Microsoft Windows Server 2016 Editions",
"cpFile": "cp037731",
"version": "2.68.64.2",
"OS": "Microsoft Windows Server 2016",
"Products": [
"HPE ProLiant DL360 Gen9 Server",
"HPE ProLiant DL380 Gen9 Server",
"HPE ProLiant DL560 Gen9 Server",
"HPE ProLiant ML350 Gen9 Server"
],
"Description": "This driver, LSI_SAS2, provides Windows Server 2016 support for HPE H2xx SAS/SATA Host Bus Adapter. ",
"Category": "Driver - Storage Controller"
},
{
"Name": "HPE Smart Array P824i-p MR 64-bit controller driver for Microsoft Windows 2016 edition.",
"cpFile": "cp034411",
"version": "6.714.18.0",
"OS": "Microsoft Windows Server 2016",
"Products": [
"HPE ProLiant DL360 Gen10 Server",
"HPE ProLiant DL380 Gen10 Server",
"HPE ProLiant DL385 Gen10 Server",
"HPE ProLiant DL560 Gen10 Server",
"HPE ProLiant DL580 Gen10 Server",
"HPE ProLiant ML350 Gen10 Server"
],
"Description": "This driver, MegaSAS2, provides Windows 64-bit support for HPE Smart Array P824i-p MR 64-bit controller",
"Category": "Driver - Storage Controller"
}
]

To The json itself should be sorted by "Name":
$Json = $Json |Sort-Object Name
To sort of everything in "Products":
$Json.Foreach{ $_.Products = $_.Products |Sort-Object }

Related

Select mid-level attribute from JMESPATH expression

I am trying to select the cluster name for a specific virtual machine using Ansible's json_query which uses JMESPATH in the backend.
I have followed the tutorial and examples at http://jmespath.org but am unable to construct the correct query.
My datastructure is as follows:
{
"datacenters": [
{
"name": "dc-a",
"clusters": [
{ "name": "cluster-a",
"hosts": [
{
"name": "host-a",
"vms": [
{
"name": "vm-a",
"summary": {
"mem": "8",
"diskGB": "78.00",
"annotation": "",
"state": "poweredOn",
"ostype": "Microsoft Windows Server 2008 R2 (64-bit)",
"cpu": "2"
}
},
{
"name": "vm-b",
"summary": {
"mem": "24",
"diskGB": "114.00",
"annotation": "",
"state": "poweredOn",
"ostype": "Microsoft Windows Server 2008 R2 (64-bit)",
"cpu": "4"
}
}]
}]
}]
}]
}
I am able to select the VM ('vm-a') using the query below but I am looking for the cluster (i.e. 'cluster-a').
datacenters[].clusters[].hosts[].vms[?name=='vm-a'].name[]
datacenters[].clusters[?contains(hosts[].vms[].name, 'vm-a')].name[]

MySql InnO DB cluster node not rejoin automatically to the Cluster

I have implemented MySQL InnoDB cluster with 3 nodes.when I stop MySql service on one of the slave node, Cluster change the slave node status to Missing state.
When I start Mysql service on stopped node Cluster not rejoin the node automatically.I need to manually rejoin the node cluster using
mysql-js>cluster.rejoinInstance('ic#ic-2:3306');
Status of My Cluster
mysql-js> cluster.status();
{
"clusterName": "MyCluster",
"defaultReplicaSet": {
"name": "default",
"primary": "ic-1:3306",
"status": "OK_NO_TOLERANCE",
"statusText": "Cluster is NOT tolerant to any failures. 1 member is not active",
"topology": {
"ic-1:3306": {
"address": "ic-1:3306",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"ic-2:3306": {
"address": "ic-2:3306",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "(MISSING)"
},
"ic-3:3306": {
"address": "ic-3:3306",
"mode": "R/O",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
}
}
}
}
Ther is any possibility to rejoin the node to cluster automatically?

Powershell Json Formatting

I need some help with formatting json data. I'm converting a table to json to be ingested into a log collector. The collector only likes json in single line format. How can I convert this json:
[
{ "Severity": "Informational",
"Type": "Milestone",
"SiteCode": "ABC",
"DateTime": 1505840220813,
"System": "Server.domain.local",
"Component": "SMS_Distribution_Point_Monitoring",
"Module": "SMS Server",
"MessageID": 2380,
"Description": "Start to evaluate package ABC001F5 on distribution point Display=\\\\Server.domain.local\\ MSWNET: SMS_SITE=ABC \\\\Server.domain.local\\."
},
{ "Severity": "Informational",
"Type": "Milestone",
"SiteCode": "ABC",
"DateTime": 1505840220787,
"System": "Server.domain.local",
"Component": "SMS_Distribution_Point_Monitoring",
"Module": "SMS Server",
"MessageID": 2384,
"Description": "Package ABC0019F on distribution point Display=\\\\Server.domain.local\\ MSWNET: SMS_SITE=ABC \\\\Server.domain.local\\ has been verified successfully."
}
]
to this in powershell when outputting to a file:
[{"Severity":"Informational","Type":"Milestone","SiteCode":"ABC","DateTime":1505840220813,"System":"Server.thecarlylegroup.local","Component":"SMS_Distribution_Point_Monitoring","Module":"SMSServer","MessageID":2380,"Description":"StarttoevaluatepackageABC001F5ondistributionpointDisplay=\\\\Server.thecarlylegroup.local\\MSWNET:SMS_SITE=ABC\\\\Server.thecarlylegroup.local\\."},
{"Severity":"Informational","Type":"Milestone","SiteCode":"ABC","DateTime":1505840220787,"System":"Server.thecarlylegroup.local","Component":"SMS_Distribution_Point_Monitoring","Module":"SMSServer","MessageID":2384,"Description":"PackageABC0019FondistributionpointDisplay=\\\\Server.thecarlylegroup.local\\MSWNET:SMS_SITE=ABC\\\\Server.thecarlylegroup.local\\hasbeenverifiedsuccessfully."}]
Assuming you get your data out of your table and into a string similar to the following:
$json = #"
[
{ "Severity": "Informational",
"Type": "Milestone",
"SiteCode": "ABC",
"DateTime": 1505840220813,
"System": "Server.domain.local",
"Component": "SMS_Distribution_Point_Monitoring",
"Module": "SMS Server",
"MessageID": 2380,
"Description": "Start to evaluate package ABC001F5 on distribution point Display=\\\\Server.domain.local\\ MSWNET: SMS_SITE=ABC \\\\Server.domain.local\\."
},
{ "Severity": "Informational",
"Type": "Milestone",
"SiteCode": "ABC",
"DateTime": 1505840220787,
"System": "Server.domain.local",
"Component": "SMS_Distribution_Point_Monitoring",
"Module": "SMS Server",
"MessageID": 2384,
"Description": "Package ABC0019F on distribution point Display=\\\\Server.domain.local\\ MSWNET: SMS_SITE=ABC \\\\Server.domain.local\\ has been verified successfully."
}
]
"#
Then you can do this (the depth was chosen arbitrarily to ensure that the entire object was converted):
$compressedJson = $json | ConvertFrom-Json | ConvertTo-Json -Compress -Depth 100
If you're working a string:
$var = (#"
[
{ "Severity": "Informational",
"Type": "Milestone",
"SiteCode": "ABC",
"DateTime": 1505840220813,
"System": "Server.domain.local",
"Component": "SMS_Distribution_Point_Monitoring",
"Module": "SMS Server",
"MessageID": 2380,
"Description": "Start to evaluate package ABC001F5 on distribution point Display=\\\\Server.domain.local\\ MSWNET: SMS_SITE=ABC \\\\Server.domain.local\\."
},
{ "Severity": "Informational",
"Type": "Milestone",
"SiteCode": "ABC",
"DateTime": 1505840220787,
"System": "Server.domain.local",
"Component": "SMS_Distribution_Point_Monitoring",
"Module": "SMS Server",
"MessageID": 2384,
"Description": "Package ABC0019F on distribution point Display=\\\\Server.domain.local\\ MSWNET: SMS_SITE=ABC \\\\Server.domain.local\\ has been verified successfully."
}
]
"# -split "`n" | % { $_.Trim() }) -join ''

How can I configure the password and username of a ClearDb MySQL database in an ARM template

Is there a way to set the PW and username of a ClearDB MySQL database in an ARM template?
Here's the resource:
{
"type": "SuccessBricks.ClearDB/databases",
"name": "[parameters('databases_cmsdbbasic_name')]",
"apiVersion": "2014-04-01",
"location": "East US 2",
"plan": {
"name": "Jupiter"
},
"tags": {},
"scale": null,
"properties": {
"hostname": "us-cdbr-azure-east2-d.cloudapp.net",
"name": "[parameters('databases_cmsdbbasic_name')]",
"id": "8C7C711AC0C0A028CE3E9D45814B868A",
"size_mb": "0",
"max_size_mb": "10240",
"status": {
"name": "Healthy",
"message": "Database is healthy and ready for use.",
"level": "Info"
}
},
"dependsOn": []
},
Based on my knowledge, it is not possible.
Publisher ClearDB does not allow user to add user and password information in the template. Currently, the user's name randomly generated by cleardb. It also does not support change user name. You need rest password on ClearDB portal.

Mongodb import json with _id

I am trying to import the following data in a mongodb collection
[
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
]
I am getting errors -
D:\mongodb\bin>mongoimport --db mopi --collection somecountry --type json --file
somecountry.json --jsonArray
connected to: 127.0.0.1
Fri Nov 07 14:20:45.149 exception:BSON representation of supplied JSON array is
too large: code FailedToParse: FailedToParse: Bad characters in value: offset:7
Fri Nov 07 14:20:45.151 [
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
]
Fri Nov 07 14:20:45.152 check 0 0
Fri Nov 07 14:20:45.153 imported 0 objects
Fri Nov 07 14:20:45.153 ERROR: encountered 1 error(s)
I'm assuming that you are showing us an abbreviation of your data. The error says that the BSON resulting from your JSON exceeds the hard 16MB limit. You can fix the problem by reformatting the data. Instead of putting multiple documents in an array and importing with --jsonArray, which restricts the total import size to 16MB, put one json document per line:
{"_id":NumberLong(1), "name": "Afghanistan", "code": "AF"},
{"_id":NumberLong(2), "name": "Aland Islands", "code": "AX"},
{"_id":NumberLong(3), "name": "Albania", "code": "AL"},
{"_id":NumberLong(4), "name": "Algeria", "code": "DZ"},
{"_id":NumberLong(5), "name": "American Samoa", "code": "AS"},
{"_id":NumberLong(6), "name": "AndorrA", "code": "AD"}
...