We at the Crystallography Open Database (COD) have been experimenting with CIF <-> JSON conversion for a while. We have arrived at a decision to map the internal representation of CIF files used by our software package cod-tools directly into JSON since v1.1. We have been using 'cod-tools' internal representation (described in Merkys et al., 2016) for some time and though it includes some redundant information, it has proven itself useful in automatically handling CIFs at the COD. Another, low redundancy method has also been proposed.
-
Top level container is an array instead of an object, thus, order of CIF datablocks (represented as objects) in an input file is retained; uniqueness of datablock names is not enforced;
-
Data items are keys of
valuessub-object, thus uniqueness of data names within a data block/save frame is enforced; -
Values are always represented as strings exactly as given in CIF file, without losing precision;
-
Types of values are stored alongside in a sub-object
typesof datablock. Thus,?value of type 'unquoted string' is distinguishable from?value of type 'quoted string' or 'textfield', reducing the need for methods to escape?and.values with special meanings; -
Values of a tag are always stored as an array; there is a sub-object
inloopof datablock, which tells whether a tag is looped or not; -
Loops, their tags and order are described in sub-array
loopsof datablock.
Converts CIF file (test.cif) to JSON (test.json):
$ cif2json test.cif > test.json
Pretty-prints converted JSON to test-pp.cif:
$ json_pp < test.json > test-pp.json