reworking of Douglas Crockford's org.json package