Skip to content

Instantly share code, notes, and snippets.

@miku
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miku/1313caaf50d685818a44 to your computer and use it in GitHub Desktop.
Save miku/1313caaf50d685818a44 to your computer and use it in GitHub Desktop.
marctojson -p -l fixtures/journals.mrc VS yaz-marcdump -i marc -o json fixtures/journals.mrc

On MARC and JSON

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'    
{
"001": "testsample1",
"005": "20091117105557.0",
"008": "840328d19831987nyufx1p o 0 a0eng d",
"010": [
{
"a": [
" 84643014 //r88"
],
"ind1": " ",
"ind2": " ",
"z": [
"sn 84011556 "
]
}
],
"022": [
{
"a": [
"0748-1985"
],
"ind1": "0",
"ind2": " "
}
],
"032": [
{
"a": [
"002051"
],
"b": [
"USPS"
],
"ind1": " ",
"ind2": " "
}
],
"035": [
{
"a": [
"ocm10569413"
],
"ind1": " ",
"ind2": " "
}
],
"037": [
{
"b": [
"Human Sciences Press, Inc., 72 5th Ave., New York, N.Y. 10011"
],
"ind1": " ",
"ind2": " "
}
],
"040": [
{
"a": [
"KSW"
],
"c": [
"KSW"
],
"d": [
"CLU",
"AIP",
"NST",
"DLC",
"NSD",
"NST",
"DLC",
"HUL",
"NST",
"NSD",
"NLM",
"NST",
"NSD",
"NST",
"NSD",
"DLC",
"NST",
"NSD",
"NST",
"CLU",
"NST",
"OCL",
"PVU"
],
"ind1": " ",
"ind2": " "
}
],
"049": [
{
"a": [
"PVUP[SERIAL]"
],
"ind1": " ",
"ind2": " "
}
],
"050": [
{
"a": [
"AC489.R3"
],
"b": [
"J68"
],
"ind1": "0",
"ind2": "0"
}
],
"210": [
{
"a": [
"J. ration. emot. ther."
],
"ind1": "0",
"ind2": " "
}
],
"222": [
{
"a": [
"Journal of rational emotive therapy"
],
"ind1": " ",
"ind2": "0"
}
],
"245": [
{
"a": [
"Journal of rational emotive therapy :"
],
"b": [
"the journal of the Institute for Rational-Emotive Therapy."
],
"ind1": "0",
"ind2": "0"
}
],
"246": [
{
"a": [
"Journal of rational-emotive therapy"
],
"ind1": "1",
"ind2": "3"
}
],
"260": [
{
"a": [
"[New York] :"
],
"b": [
"The Institute,"
],
"c": [
"1983-1987."
],
"ind1": " ",
"ind2": " "
}
],
"300": [
{
"a": [
"5 v. :"
],
"b": [
"ill. ;"
],
"c": [
"26 cm."
],
"ind1": " ",
"ind2": " "
}
],
"310": [
{
"a": [
"Two no. a year"
],
"ind1": " ",
"ind2": " "
}
],
"362": [
{
"a": [
"Vol. 1, no. 1 (fall 1983)-v. 5, no. 4 (winter 1987)."
],
"ind1": "0",
"ind2": " "
}
],
"500": [
{
"a": [
"Title from cover."
],
"ind1": " ",
"ind2": " "
},
{
"a": [
"Vols. for u003cspring 1985-u003e published by Human Sciences Press, Inc."
],
"ind1": " ",
"ind2": " "
}
],
"515": [
{
"a": [
"Vol. 1 has only one issue."
],
"ind1": " ",
"ind2": " "
}
],
"650": [
{
"a": [
"Rational-emotive psychotherapy"
],
"ind1": " ",
"ind2": "0",
"v": [
"Periodicals."
]
},
{
"a": [
"Cognitive therapy"
],
"ind1": " ",
"ind2": "0",
"v": [
"Periodicals."
]
},
{
"a": [
"Psychotherapy"
],
"ind1": " ",
"ind2": "2",
"v": [
"periodicals."
]
}
],
"710": [
{
"a": [
"Institute for Rational-Emotive Therapy (New York, N.Y.)"
],
"ind1": "2",
"ind2": " "
}
],
"780": [
{
"ind1": "0",
"ind2": "0",
"t": [
"Rational living"
],
"w": [
"(OCLC)1763461",
"(DLC) 72000647"
],
"x": [
"0034-0049"
]
}
],
"785": [
{
"ind1": "0",
"ind2": "0",
"t": [
"Journal of rational-emotive and cognitive-behavior therapy"
],
"w": [
"(DLC) 88648219",
"(OCoLC)16307814"
],
"x": [
"0894-9085"
]
}
],
"leader": {
"ba": "361",
"cs": "a",
"ic": "2",
"impldef": "s 1a ",
"length": "1571",
"lol": "4",
"losp": "5",
"raw": "01571cas a22003611a 4500",
"sfcl": "2",
"status": "c",
"type": "a"
}
}
{
"leader":"01571cas a22003611a 450 ",
"fields":
[
{
"001":"testsample1"
},
{
"005":"20091117105557.0"
},
{
"008":"840328d19831987nyufx1p o 0 a0eng d"
},
{
"010":
{
"subfields":
[
{
"a":" 84643014 //r88"
},
{
"z":"sn 84011556 "
}
],
"ind1":" ",
"ind2":" "
}
},
{
"022":
{
"subfields":
[
{
"a":"0748-1985"
}
],
"ind1":"0",
"ind2":" "
}
},
{
"032":
{
"subfields":
[
{
"a":"002051"
},
{
"b":"USPS"
}
],
"ind1":" ",
"ind2":" "
}
},
{
"035":
{
"subfields":
[
{
"a":"ocm10569413"
}
],
"ind1":" ",
"ind2":" "
}
},
{
"037":
{
"subfields":
[
{
"b":"Human Sciences Press, Inc., 72 5th Ave., New York, N.Y. 10011"
}
],
"ind1":" ",
"ind2":" "
}
},
{
"040":
{
"subfields":
[
{
"a":"KSW"
},
{
"c":"KSW"
},
{
"d":"CLU"
},
{
"d":"AIP"
},
{
"d":"NST"
},
{
"d":"DLC"
},
{
"d":"NSD"
},
{
"d":"NST"
},
{
"d":"DLC"
},
{
"d":"HUL"
},
{
"d":"NST"
},
{
"d":"NSD"
},
{
"d":"NLM"
},
{
"d":"NST"
},
{
"d":"NSD"
},
{
"d":"NST"
},
{
"d":"NSD"
},
{
"d":"DLC"
},
{
"d":"NST"
},
{
"d":"NSD"
},
{
"d":"NST"
},
{
"d":"CLU"
},
{
"d":"NST"
},
{
"d":"OCL"
},
{
"d":"PVU"
}
],
"ind1":" ",
"ind2":" "
}
},
{
"049":
{
"subfields":
[
{
"a":"PVUP[SERIAL]"
}
],
"ind1":" ",
"ind2":" "
}
},
{
"050":
{
"subfields":
[
{
"a":"AC489.R3"
},
{
"b":"J68"
}
],
"ind1":"0",
"ind2":"0"
}
},
{
"210":
{
"subfields":
[
{
"a":"J. ration. emot. ther."
}
],
"ind1":"0",
"ind2":" "
}
},
{
"222":
{
"subfields":
[
{
"a":"Journal of rational emotive therapy"
}
],
"ind1":" ",
"ind2":"0"
}
},
{
"245":
{
"subfields":
[
{
"a":"Journal of rational emotive therapy :"
},
{
"b":"the journal of the Institute for Rational-Emotive Therapy."
}
],
"ind1":"0",
"ind2":"0"
}
},
{
"246":
{
"subfields":
[
{
"a":"Journal of rational-emotive therapy"
}
],
"ind1":"1",
"ind2":"3"
}
},
{
"260":
{
"subfields":
[
{
"a":"[New York] :"
},
{
"b":"The Institute,"
},
{
"c":"1983-1987."
}
],
"ind1":" ",
"ind2":" "
}
},
{
"300":
{
"subfields":
[
{
"a":"5 v. :"
},
{
"b":"ill. ;"
},
{
"c":"26 cm."
}
],
"ind1":" ",
"ind2":" "
}
},
{
"310":
{
"subfields":
[
{
"a":"Two no. a year"
}
],
"ind1":" ",
"ind2":" "
}
},
{
"362":
{
"subfields":
[
{
"a":"Vol. 1, no. 1 (fall 1983)-v. 5, no. 4 (winter 1987)."
}
],
"ind1":"0",
"ind2":" "
}
},
{
"500":
{
"subfields":
[
{
"a":"Title from cover."
}
],
"ind1":" ",
"ind2":" "
}
},
{
"500":
{
"subfields":
[
{
"a":"Vols. for <spring 1985-> published by Human Sciences Press, Inc."
}
],
"ind1":" ",
"ind2":" "
}
},
{
"515":
{
"subfields":
[
{
"a":"Vol. 1 has only one issue."
}
],
"ind1":" ",
"ind2":" "
}
},
{
"650":
{
"subfields":
[
{
"a":"Rational-emotive psychotherapy"
},
{
"v":"Periodicals."
}
],
"ind1":" ",
"ind2":"0"
}
},
{
"650":
{
"subfields":
[
{
"a":"Cognitive therapy"
},
{
"v":"Periodicals."
}
],
"ind1":" ",
"ind2":"0"
}
},
{
"650":
{
"subfields":
[
{
"a":"Psychotherapy"
},
{
"v":"periodicals."
}
],
"ind1":" ",
"ind2":"2"
}
},
{
"710":
{
"subfields":
[
{
"a":"Institute for Rational-Emotive Therapy (New York, N.Y.)"
}
],
"ind1":"2",
"ind2":" "
}
},
{
"780":
{
"subfields":
[
{
"t":"Rational living"
},
{
"x":"0034-0049"
},
{
"w":"(OCLC)1763461"
},
{
"w":"(DLC) 72000647"
}
],
"ind1":"0",
"ind2":"0"
}
},
{
"785":
{
"subfields":
[
{
"t":"Journal of rational-emotive and cognitive-behavior therapy"
},
{
"x":"0894-9085"
},
{
"w":"(DLC) 88648219"
},
{
"w":"(OCoLC)16307814"
}
],
"ind1":"0",
"ind2":"0"
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment