Home > database >  How to Format the Output to file
How to Format the Output to file

Time:02-19

Ok now i post my complete JSON to get Finished help :)

{
    "MapName": "Banov",
    "CameraPosition": [
        14529.142578125,
        368.8961181640625,
        2025.468505859375
    ],
    "EditorObjects": [
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                16112.0,
                578.5066528320313,
                4247.9990234375
            ],
            "Orientation": [
                -43.66538619995117,
                0.0,
                0.0
            ],
            "Scale": 0.9999992847442627,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5589.42041015625,
                196.24301147460938,
                1670.6236572265626
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5448.6962890625,
                193.07176208496095,
                2159.627197265625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5098.7646484375,
                196.5845947265625,
                2797.101318359375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5418.6923828125,
                197.42132568359376,
                2673.85595703125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5647.73486328125,
                204.05783081054688,
                2943.16943359375
            ],
            "Orientation": [
                -44.99999237060547,
                0.0,
                0.0
            ],
            "Scale": 0.9999999403953552,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5776.501953125,
                197.58221435546876,
                2348.202880859375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                6256.09423828125,
                215.8865966796875,
                2330.556640625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                6396.64453125,
                223.6721954345703,
                1988.18115234375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                6402.6201171875,
                205.75247192382813,
                1309.4581298828126
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                7036.60986328125,
                206.21649169921876,
                1575.7742919921876
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                7693.6328125,
                207.34384155273438,
                1974.135498046875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                8652.7236328125,
                217.5430908203125,
                2747.70263671875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                9729.744140625,
                233.95138549804688,
                3747.239990234375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                11405.0673828125,
                240.86843872070313,
                3899.416015625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                11533.1572265625,
                233.01821899414063,
                3530.836669921875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                11964.3388671875,
                252.64285278320313,
                3163.984375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                12371.12890625,
                336.7644348144531,
                2424.14453125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                12916.7314453125,
                314.4809265136719,
                642.4998168945313
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                13634.0732421875,
                521.6116943359375,
                3607.91064453125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                12699.0087890625,
                406.08587646484377,
                2158.10009765625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                11981.828125,
                368.830078125,
                1799.614501953125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                10969.8271484375,
                303.9376525878906,
                1888.0809326171876
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                9974.4931640625,
                250.86526489257813,
                1675.0009765625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                9222.4306640625,
                234.9065704345703,
                1610.0352783203126
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5532.53125,
                195.36331176757813,
                1375.9154052734376
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                5177.12646484375,
                193.35589599609376,
                550.585693359375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4731.4248046875,
                189.90444946289063,
                494.9140625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4362.8974609375,
                189.88381958007813,
                243.05331420898438
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                3619.464599609375,
                215.0565185546875,
                309.6984558105469
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                2665.703369140625,
                204.01568603515626,
                771.5391845703125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                2315.38720703125,
                213.45166015625,
                1823.015869140625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                573.829833984375,
                232.47854614257813,
                3027.85400390625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                434.58770751953127,
                224.9228515625,
                2781.3046875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                1234.419189453125,
                238.2891845703125,
                80.10952758789063
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                1233.64208984375,
                225.33631896972657,
                4226.62939453125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                1133.495361328125,
                219.12918090820313,
                3943.985595703125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                1658.0262451171876,
                216.08071899414063,
                4604.31494140625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                2266.79150390625,
                254.8126220703125,
                5348.03076171875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                2763.8916015625,
                218.3936767578125,
                5650.4228515625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                2908.519287109375,
                210.48126220703126,
                6071.58642578125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                1248.7822265625,
                237.6549072265625,
                10573.962890625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                661.3869018554688,
                247.23915100097657,
                11698.2080078125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                433.6549987792969,
                252.18695068359376,
                11875.921875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                412.8946838378906,
                270.5828857421875,
                13276.029296875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                924.1931762695313,
                263.74395751953127,
                13223.30859375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                3994.21875,
                261.6960754394531,
                13704.8408203125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4210.296875,
                253.06817626953126,
                13629.318359375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4342.7880859375,
                249.7008056640625,
                13315.22265625
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4409.97705078125,
                234.2764892578125,
                11167.2958984375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4867.5361328125,
                229.57009887695313,
                10650.3193359375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4981.54736328125,
                225.56643676757813,
                10127.9365234375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                3894.4765625,
                203.59176635742188,
                3319.906982421875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4215.00732421875,
                234.03945922851563,
                2586.14111328125
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4062.798828125,
                219.2050018310547,
                3968.34521484375
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        },
        {
            "Type": "SV_IBarrel1",
            "DisplayName": "SV_IBarrel1",
            "Position": [
                4052.447265625,
                202.1627655029297,
                3555.311279296875
            ],
            "Orientation": [
                0.0,
                -0.0,
                -0.0
            ],
            "Scale": 1.0,
            "Flags": 2147483647
        }
    ],
    "EditorDeletedObjects": []
}

I am able to get my positions. But now he list all Numbers behind each other like

[16112.0,578.5066528320313,4247.9990234375,5589.42041015625,196.24301147460938,1670.6236572265626,5448.6962890625,193.07176208496095,2159.627197265625,5098.7646484375,196.5845947265625,2797.101318359375,5418.6923828125,197.42132568359376,2673.85595703125,5647.73

i Try alle the time to get an array from every 3 points of position like:

[16112.0,578.5066528320313,4247.9990234375],
[5589.42041015625,196.24301147460938,1670.6236572265626],
[5448.6962890625,193.07176208496095,2159.627197265625],
[5098.7646484375,196.5845947265625,2797.101318359375,5418.6923828125]

And if is posibile i want only max 5 or 4 Numbers behind the "." like

[16112.0,578.50665,4247.9990],
[5589.42041,196.24301,1670.62365],
[5448.69628,193.07176,2159.62719],
[5098.76464,196.58459,2797.101318]

I hope it easy and possible to get this working My actually probably working code^^

$input = (Get-Content $path) | ConvertFrom-Json 
$input.EditorObjects.Position | ConvertTo-Json 

$Inhalttrennen = $input.Split(",")
$Inhalttrennen[0] = '$X'
$Inhalttrennen[1] = '$H'
$Inhalttrennen[2] = '$Z'

    $Ausgabe = "[$($X),$($H),$($Z)]" | Set-Content $Ausgabepfad

CodePudding user response:

To format the Position numeric values in your JSON file the way you want, you can do:

$path        = 'D:\Test\testfile.json'
$Ausgabepfad = 'D:\Test\result.txt'

(Get-Content -Path $path -Raw | ConvertFrom-Json).EditorObjects | ForEach-Object {
    $positions = for ($i = 0; $i -lt [math]::Min(3, $_.Position.Count); $i  ) {
        # if your machines locale number settings use a decimal POINT, you could do
        # '{0:F4}' -f $_.Position[$i]

        # but if it is using a decimal COMMA on numbers (like mine), use
        $_.Position[$i].ToString("F4", [cultureinfo]::InvariantCulture)
    }
    # now join the (max) 3 rounded numbers with a comma and place between square brackets
    '[{0}]' -f ($positions -join ',')
} | Set-Content -Path $Ausgabepfad

Output

[6256.0942,215.8866,2330.5566]
[6396.6445,223.6722,1988.1812]
[6402.6201,205.7525,1309.4581]
[7036.6099,206.2165,1575.7743]
[7693.6328,207.3438,1974.1355]
[8652.7236,217.5431,2747.7026]
[9729.7441,233.9514,3747.2400]
[11405.0674,240.8684,3899.4160]
[11533.1572,233.0182,3530.8367]
[11964.3389,252.6429,3163.9844]
[12371.1289,336.7644,2424.1445]
[12916.7314,314.4809,642.4998]
[13634.0732,521.6117,3607.9106]
[12699.0088,406.0859,2158.1001]
[11981.8281,368.8301,1799.6145]
[10969.8271,303.9377,1888.0809]
[9974.4932,250.8653,1675.0010]
[9222.4307,234.9066,1610.0353]
[5532.5313,195.3633,1375.9154]
[5177.1265,193.3559,550.5857]
[4731.4248,189.9044,494.9141]
[4362.8975,189.8838,243.0533]
[3619.4646,215.0565,309.6985]
[2665.7034,204.0157,771.5392]
[2315.3872,213.4517,1823.0159]
[573.8298,232.4785,3027.8540]
[434.5877,224.9229,2781.3047]
[1234.4192,238.2892,80.1095]
[1233.6421,225.3363,4226.6294]
[1133.4954,219.1292,3943.9856]
[1658.0262,216.0807,4604.3149]
[2266.7915,254.8126,5348.0308]
[2763.8916,218.3937,5650.4229]
[2908.5193,210.4813,6071.5864]
[1248.7822,237.6549,10573.9629]
[661.3869,247.2392,11698.2080]
[433.6550,252.1870,11875.9219]
[412.8947,270.5829,13276.0293]
[924.1932,263.7440,13223.3086]
[3994.2188,261.6961,13704.8408]
[4210.2969,253.0682,13629.3184]
[4342.7881,249.7008,13315.2227]
[4409.9771,234.2765,11167.2959]
[4867.5361,229.5701,10650.3193]
[4981.5474,225.5664,10127.9365]
[3894.4766,203.5918,3319.9070]
[4215.0073,234.0395,2586.1411]
[4062.7988,219.2050,3968.3452]
[4052.4473,202.1628,3555.3113]
  • Related