arrays - Use Get-Content and split json file into 3 parts -


if have json file in following format:

{     "server" : {         "name" : "myubuntuserver1",         "imageref" : "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",         "flavorref" : "9" } } {     "server" : {         "name" : "myubuntuserver2",         "imageref" : "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",         "flavorref" : "6" } } {     "server" : {         "name" : "myubuntuserver3",         "imageref" : "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",         "flavorref" : "3" } } 

how split according number of servers detected in file , assign each block array item, i.e.

array item 0

{     "server" : {         "name" : "myubuntuserver1",         "imageref" : "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",         "flavorref" : "9" } } 

array item 1

{     "server" : {         "name" : "myubuntuserver2",         "imageref" : "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",         "flavorref" : "6" } } 

array item 2

{     "server" : {         "name" : "myubuntuserver3",         "imageref" : "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",         "flavorref" : "3" } } 

this code far:

$file = "servers.json" $request = get-content $file createserver $request 

i want split file segments according server , wrap $request assignment , createserver function in loop , pass each item in array through.

so like:

$file = "servers.json" $request = get-content $file  #split file 3 here , assign array  foreach ($request in $array) {     createserver $request } 

how accomplish in powershell v2?

the json format wrong, valid format:

{     "servers": [         {             "name": "myubuntuserver1",             "imageref": "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",             "flavorref": "9"         },         {             "name": "myubuntuserver1",             "imageref": "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",             "flavorref": "9"         },         {             "name": "myubuntuserver1",             "imageref": "3afe97b2-26dc-49c5-a2cc-a2fc8d80c001",             "flavorref": "9"         }     ] } 

where can iterate inside servers key value array. hope help.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -