Helper function for schema_to_json that takes a schema list and file
        object and writes the schema list to the file object with json.dump
508498
def _schema_to_json_file_object(self, schema_list, file_obj):
        
        json.dump(schema_list, file_obj, indent=2, sort_keys=True)
262600
def _write_json(file, contents):
    """"""
    with open(file, 'w') as f:
        return json.dump(contents, f, indent=2, sort_keys=True)
959103
def json_dump(obj,       # type: Any
              fp,        # type: IO[str]
              **kwargs   # type: Any
             ):  # type: (...) -> None
    
    if six.PY2:
        kwargs['encoding'] = 'utf-8'
    json.dump(convert_to_dict(obj), fp, **kwargs)
971237
def _build_schema(self, s):
        
        w = self._whatis(s)
        if w == self.IS_LIST:
            w0 = self._whatis(s[0])
            js = {"type": "array",
                  "items": {"type": self._jstype(w0, s[0])}}
        elif w == self.IS_DICT:
            js = {"type": "object",
                  "properties": {key: self._build_schema(val) for key, val in s.items()}}
            req = [key for key, val in s.items() if not val.is_optional]
            if req:
                js["required"] = req
        else:
            js = {"type": self._jstype(w, s)}
        for k, v in self._json_schema_keys.items():
            if k not in js:
                js[k] = v
        return js
385572
def backup(schema, uuid, export_filter, export_format, filename, pretty, export_all, omit):
    """"""

    export_format = export_format.upper()

    if pretty:
        indent = 4
    else:
        indent = 0

    f = None

    if filename:
        try:
            f = open(filename, 'w')
        except (IOError, PermissionError) as e:
            backup_log('Could not open output file for writing:', exc=True, lvl=error)
            return

    def output(what, convert=False):
        """Output the backup in a specified format."""

        if convert:
            if export_format == 'JSON':
                data = json.dumps(what, indent=indent)
            else:
                data = ""
        else:
            data = what

        if not filename:
            print(data)
        else:
            f.write(data)

    if schema is None:
        if export_all is False:
            backup_log('No schema given.', lvl=warn)
            return
        else:
            schemata = objectmodels.keys()
    else:
        schemata = [schema]

    all_items = {}

    for schema_item in schemata:
        model = objectmodels[schema_item]

        if uuid:
            obj = model.find({'uuid': uuid})
        elif export_filter:
            obj = model.find(literal_eval(export_filter))
        else:
            obj = model.find()

        items = []
        for item in obj:
            fields = item.serializablefields()
            for field in omit:
                try:
                    fields.pop(field)
                except KeyError:
                    pass
            items.append(fields)

        all_items[schema_item] = items

        # if pretty is True:
        #    output('\n// Objectmodel: ' + schema_item + '\n\n')
        # output(schema_item + ' = [\n')

    output(all_items, convert=True)

    if f is not None:
        f.flush()
        f.close()
340273
def _serialize_json(obj, fp):
    
    json.dump(obj, fp, indent=4, default=serialize)
1295802
def dump_as_json(record, output_file):
    
    def default_func(value):
        """
        Default conversion for JSON value.
        """
        if isinstance(value, frozenset):
            return sorted(value)
        raise TypeError(repr(value) + " is not JSON serializable")

    converted_record = record._replace(
        ordered_statistics=[x._asdict() for x in record.ordered_statistics])
    json.dump(
        converted_record._asdict(), output_file,
        default=default_func, ensure_ascii=False)
    output_file.write(os.linesep)
275570
def schema_digest(self) -> str:
        
        res = self.schema._node_digest()
        res["config"] = True
        return json.dumps(res)
912200
def dump(self, obj):
        
        if self.schema_class:
            obj = self.schema_class().dump(obj).data
        else:
            obj = obj['metadata']
        return super(MARCXMLSerializer, self).dump(obj)
9930
def export_for_schema(self):
        
        if self.options_map:
            return dict((str(key), str(value)) for key, value in self.options_map.items())
        return "{'class': '%s'}" % (self.name, )
552200
def dumps(self, blob):
        

        return json.dumps(
            blob, indent=self.indent, sort_keys=True,
            separators=self.separators,
        )
1206877
def to_json(self):
        
        data = json.dumps(self)

        out = u'{"%s":%s}' % (self.schema['title'], data)
        return out
21441
def get_json_schema(filename):
    
    file_path = os.path.join("schemas", filename)
    with open(file_path) as f:
        schema = yaml.load(f)
    return schema
503032
public static <T> void writeListTo(Writer writer, List<T> messages, Schema<T> schema,
            boolean numeric) throws IOException
    {
        final JsonGenerator generator = DEFAULT_JSON_FACTORY.createJsonGenerator(writer);
        try
        {
            writeListTo(generator, messages, schema, numeric);
        }
        finally
        {
            generator.close();
        }
    }
538824
public void dumpSchema() {
        String fileName = m_config.root + m_config.app + ".xml";
        m_logger.info("Writing schema to: {}", fileName);
        File schemaFile = new File(fileName);
        schemaFile.getParentFile().mkdirs();
        try (FileWriter fileWriter = new FileWriter(schemaFile)) {
            fileWriter.write(m_appDef.toDoc().toXML(true));
        } catch (IOException ex) {
            m_logger.error("Unable to dump schema file '" + fileName + "'", ex);
            throw new RuntimeException(ex);
        }
    }
567297
def write_object_to_file(self, obj, path='.', filename=None):
        """"""
        output = self.json_dumps(obj) + '\n'
        if filename is None:
            filename = self.safe_filename(obj['_type'], obj['_id'])
        filename = os.path.join(path, filename)
        self.pr_inf("Writing to file: " + filename)
        with open(filename, 'w') as f:
            f.write(output)
        # self.pr_dbg("Contents: " + output)
        return filename
945212
def to_json_file(self, json_file_path):
        
        with open(json_file_path, "w", encoding='utf-8') as writer:
            writer.write(self.to_json_string())