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. 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 was also 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 are not enforced;
-
Data items are keys of
values
sub-object, thus uniqueness of data names within a data block / save frame are enforced; -
Values are always represented as strings exactly as given in CIF file, without losing any precisions;
-
Types of values are stored alongside in a sub-object
types
of datablock. Thus,?
value of type 'unquoted string' is easily distinguishable from?
value of type 'quoted string' or 'textfield', reducing the need of methods to escape?
and.
values with special meanings; -
Values of a tag are always put in an array; there is a sub-object
inloop
of datablock, which tells whether a tag is looped or not; -
Loops, their tags and order are described in sub-array
loops
of datablock.
Converts CIF file to JSON:
$> cif2json
test.cif>
test.json
Pretty-prints converted JSON:
$> json_pp <
test.json>
test-pp.json