简体   繁体   中英

Convert JSON to plist use PowerShell

convert JSON to plist have many ways, The most convenient is to use commands under the apple system, or to use online generation tools, But PowerShell does not provide direct commands, I found a project in GitHub, which can be easily converted for simple JSON, But for some slightly complex JSON, there will be some problems after conversion

project Address: https://github.com/msftrncs/PwshJSONtoPList

Existing problems:

Some arrays were not converted correctly

I recorded a video demo https://www57.zippyshare.com/v/krihd4Y8/file.html

related files https://www57.zippyshare.com/v/84wYYTRx/file.html

powershell Script code:

. '.\ConvertTo-PList.ps1' # Put ConvertTo-PList.ps1 in the same directory
Get-Content "test.json" | ConvertFrom-Json |
ConvertTo-Plist -Indent "`t" -StateEncodingAs 'UTF-8' |
Set-Content 'Generated.plist' -Encoding 'UTF8'

test.json:

{
  "ACPI": {
    "DSDT": {
      "Debug": false,
      "DropOEM_DSM": false,
      "Fixes": {
        "AddDTGP": false,
        "FixHPET": false,
        "FixRTC": false,
        "FixShutdown": false
      },
      "Patches": [
        {
          "Comment": "change SAT0 to SATA",
          "Disabled": false,
          "Find": "U0FUMA==",
          "Replace": "U0FUQQ=="
        },
        {
          "Comment": "change HECI to IMEI",
          "Disabled": false,
          "Find": "SEVDSQ==",
          "Replace": "SU1FSQ=="
        }
      ],
      "ReuseFFFF": false
    },
    "DropTables": [
      {
        "Signature": "DMAR"
      },
      {
        "Signature": "MATS"
      }
    ],
    "FixHeaders": true,
    "SSDT": {
      "DropOem": false,
      "Generate": {
        "CStates": true,
        "PStates": true
      }
    }
  },
  "GUI": {
    "Custom": {
      "Entries": [
        {
          "Disabled": false,
          "FullTitle": "MAC OS X",
          "Hidden": false,
          "InjectKexts": true,
          "NoCaches": true,
          "Type": "OSX",
          "Volume": "2D4A5E3A-04FC-3041-471B-8A1622089D19"
        },
        {
          "Disabled": false,
          "FullTitle": "WIN",
          "Hidden": false,
          "Type": "Windows",
          "Volume": "2BDB20A2-1E67-4AE2-753D-D85E9A410000"
        }
      ]
    },
    "Hide": [
      "Preboot",
      "Recovery",
      "BOOTX64.EFI",
      "DATA"
    ]
  },
  "KernelAndKextPatches": {
    "ForceKextsToLoad": [
      "\\System\\Library\\Extensions\\IONetworkingFamily.kext"
    ],
    "KextsToPatch": [
      {
        "Comment": "External icons patch",
        "Disabled": false,
        "Find": "RXh0ZXJuYWw=",
        "InfoPlistPatch": false,
        "Name": "AppleAHCIPort",
        "Replace": "SW50ZXJuYWw="
      },
      {
        "Comment": "Enable TRIM for SSD",
        "Disabled": false,
        "Find": "AEFQUExFIFNTRAA=",
        "InfoPlistPatch": false,
        "Name": "com.apple.iokit.IOAHCIBlockStorage",
        "Replace": "AAAAAAAAAAAAAAA="
      }
    ]
  }
}

Generated.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ACPI</key>
    <dict>
        <key>DSDT</key>
        <dict>
            <key>Debug</key>
            <false/>
            <key>DropOEM_DSM</key>
            <false/>
            <key>Fixes</key>
            <string>@{AddDTGP=False; FixHPET=False; FixRTC=False; FixShutdown=False}</string>
            <key>Patches</key>
            <string> </string>
            <key>ReuseFFFF</key>
            <false/>
        </dict>
        <key>DropTables</key>
        <array>
            <string>@{Signature=DMAR}</string>
            <string>@{Signature=MATS}</string>
        </array>
        <key>FixHeaders</key>
        <true/>
        <key>SSDT</key>
        <dict>
            <key>DropOem</key>
            <false/>
            <key>Generate</key>
            <string>@{CStates=True; PStates=True}</string>
        </dict>
    </dict>
    <key>GUI</key>
    <dict>
        <key>Custom</key>
        <dict>
            <key>Entries</key>
            <string> </string>
        </dict>
        <key>Hide</key>
        <array>
            <string>Preboot</string>
            <string>Recovery</string>
            <string>BOOTX64.EFI</string>
            <string>DATA</string>
        </array>
    </dict>
    <key>KernelAndKextPatches</key>
    <dict>
        <key>ForceKextsToLoad</key>
        <array>
            <string>\System\Library\Extensions\IONetworkingFamily.kext</string>
        </array>
        <key>KextsToPatch</key>
        <array>
            <string>@{Comment=External icons patch; Disabled=False; Find=RXh0ZXJuYWw=; InfoPlistPatch=False; Name=AppleAHCIPort; Replace=SW50ZXJuYWw=}</string>
            <string>@{Comment=Enable TRIM for SSD; Disabled=False; Find=AEFQUExFIFNTRAA=; InfoPlistPatch=False; Name=com.apple.iokit.IOAHCIBlockStorage; Replace=AAAAAAAAAAAAAAA=}</string>
        </array>
    </dict>
</dict>
</plist>

err Pic: 在此处输入图像描述

The version I see here also has a -Depth parameter.

If I use that on your json and set the Depth to 4 (or higher) with

$json | ConvertFrom-Json | ConvertTo-Plist -Indent "`t" -StateEncodingAs 'UTF-8' -Depth 4

it produces this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ACPI</key>
    <dict>
        <key>DSDT</key>
        <dict>
            <key>Debug</key>
            <false/>
            <key>DropOEM_DSM</key>
            <false/>
            <key>Fixes</key>
            <dict>
                <key>AddDTGP</key>
                <false/>
                <key>FixHPET</key>
                <false/>
                <key>FixRTC</key>
                <false/>
                <key>FixShutdown</key>
                <false/>
            </dict>
            <key>Patches</key>
            <array>
                <dict>
                    <key>Comment</key>
                    <string>change SAT0 to SATA</string>
                    <key>Disabled</key>
                    <false/>
                    <key>Find</key>
                    <string>U0FUMA==</string>
                    <key>Replace</key>
                    <string>U0FUQQ==</string>
                </dict>
                <dict>
                    <key>Comment</key>
                    <string>change HECI to IMEI</string>
                    <key>Disabled</key>
                    <false/>
                    <key>Find</key>
                    <string>SEVDSQ==</string>
                    <key>Replace</key>
                    <string>SU1FSQ==</string>
                </dict>
            </array>
            <key>ReuseFFFF</key>
            <false/>
        </dict>
        <key>DropTables</key>
        <array>
            <dict>
                <key>Signature</key>
                <string>DMAR</string>
            </dict>
            <dict>
                <key>Signature</key>
                <string>MATS</string>
            </dict>
        </array>
        <key>FixHeaders</key>
        <true/>
        <key>SSDT</key>
        <dict>
            <key>DropOem</key>
            <false/>
            <key>Generate</key>
            <dict>
                <key>CStates</key>
                <true/>
                <key>PStates</key>
                <true/>
            </dict>
        </dict>
    </dict>
    <key>GUI</key>
    <dict>
        <key>Custom</key>
        <dict>
            <key>Entries</key>
            <array>
                <dict>
                    <key>Disabled</key>
                    <false/>
                    <key>FullTitle</key>
                    <string>MAC OS X</string>
                    <key>Hidden</key>
                    <false/>
                    <key>InjectKexts</key>
                    <true/>
                    <key>NoCaches</key>
                    <true/>
                    <key>Type</key>
                    <string>OSX</string>
                    <key>Volume</key>
                    <string>2D4A5E3A-04FC-3041-471B-8A1622089D19</string>
                </dict>
                <dict>
                    <key>Disabled</key>
                    <false/>
                    <key>FullTitle</key>
                    <string>WIN</string>
                    <key>Hidden</key>
                    <false/>
                    <key>Type</key>
                    <string>Windows</string>
                    <key>Volume</key>
                    <string>2BDB20A2-1E67-4AE2-753D-D85E9A410000</string>
                </dict>
            </array>
        </dict>
        <key>Hide</key>
        <array>
            <string>Preboot</string>
            <string>Recovery</string>
            <string>BOOTX64.EFI</string>
            <string>DATA</string>
        </array>
    </dict>
    <key>KernelAndKextPatches</key>
    <dict>
        <key>ForceKextsToLoad</key>
        <array>
            <string>\System\Library\Extensions\IONetworkingFamily.kext</string>
        </array>
        <key>KextsToPatch</key>
        <array>
            <dict>
                <key>Comment</key>
                <string>External icons patch</string>
                <key>Disabled</key>
                <false/>
                <key>Find</key>
                <string>RXh0ZXJuYWw=</string>
                <key>InfoPlistPatch</key>
                <false/>
                <key>Name</key>
                <string>AppleAHCIPort</string>
                <key>Replace</key>
                <string>SW50ZXJuYWw=</string>
            </dict>
            <dict>
                <key>Comment</key>
                <string>Enable TRIM for SSD</string>
                <key>Disabled</key>
                <false/>
                <key>Find</key>
                <string>AEFQUExFIFNTRAA=</string>
                <key>InfoPlistPatch</key>
                <false/>
                <key>Name</key>
                <string>com.apple.iokit.IOAHCIBlockStorage</string>
                <key>Replace</key>
                <string>AAAAAAAAAAAAAAA=</string>
            </dict>
        </array>
    </dict>
</dict>
</plist>

Apparently you have an older version of the script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM