Different JSON serializations of MARC records (yaz vs marctools).
$ marctojson -p -l fixtures/journals.mrc
versus
$ yaz-marcdump -i marc -o json fixtures/journals.mrc
The marctojson
output format was created with an indexing use case in mind, but seems to be a bit more suitable for programmatic access as well:
>>> mt = json.loads(open("marctools.json").read())
>>> yz = json.loads(open("yaz.json").read())
To find the second value of the subfield w
of the first 780
field one would write with the marctools output:
>>> mt['780'][0]['w'][1]
u'(DLC) 72000647'
Whereas the yaz output is a bit more verbose and opaque, since the main field data structure is a list. Either one knows the field positions (e.g. 26 and 3):
>>> yz['fields'][26]['780']['subfields'][3]['w']
u'(DLC) 72000647'
Or one loops over the fields:
>>> values = []
>>> for field in yz['fields']:
... for key, value in field.iteritems():
... if key == '780':
... for subfield in value['subfields']:
... for kk, vv in subfield.iteritems():
... if kk == 'w':
... values.append(vv)
>>> values[1]
u'(DLC) 72000647'