plist と json を相互変換する

iOSやMac OS Xで使用されるplist形式(プロパティリスト)と、

Mac OS Xを使っているならターミナルからplutilコマンドで簡単に相互変換できます。


plutil -convert json input.plist -r -o output.json

-r オプションはJSONを整形して出力するためのオプションで、無くても動作します。
-o オプション(出力先指定)を省略した場合、変換元ファイル(input.plist)を上書きするので注意しましょう。


plutil -convert json input.json -o output.plist

plistからjsonの変換と同様、-o オプションを省略した場合、-rオプションで指定した変換元ファイルを上書きするので注意しましょう。

plutil の詳しい使い方については man plutil(下記)が参考になります。

PLUTIL(1)                 BSD General Commands Manual                PLUTIL(1)

     plutil -- property list utility

     plutil [command_option] [other_options] file

     plutil can be used to check the syntax of property list files, or convert
     a plist file from one format to another.  Specifying - as an input file
     reads from stdin.

     The first argument indicates the operation to perform, one of:

     -help         Show the usage information for the command and exit.

     -p            Print the property list in a human-readable fashion. The
                   output format is not stable and not designed for machine
                   parsing. The purpose of this command is to be able to eas-
                   ily read the contents of a plist file, no matter what for-
                   mat it is in.

     -lint         Check the named property list files for syntax errors.
                   This is the default command option if none is specified.

     -convert fmt  Convert the named file to the indicated format and write
                   back to the file system.  If the file can't be loaded due
                   to invalid syntax, the operation fails.

                   fmt is one of:  xml1, for version 1 of the XML plist format
                                   binary1, for version 1 of the binary plist
                                   format json, for the JSON format

     There are a few additional options:

     --            Specifies that all further arguments are file names

     -s            Don't print anything on success.

     -r            For JSON, add whitespace and indentation to make the output
                   more human-readable.

     -o path       Specify an alternate path name for the result of the -con-
                   vert operation; this option is only useful with a single
                   file to be converted.  Specifying - as the path outputs to

     -e extension  Specify an alternate extension for converted files, and the
                   output file names are otherwise the same.

     The plutil command exits 0 on success, and 1 on failure.


     The plutil command obeys no one's rules but its own.

     The plutil command first appeared in Mac OS X 10.2.

Mac OS X                        August 30, 2002                       Mac OS X