write json in canonical json format
15649
def json2file(data, filename, encoding='utf-8'):
    
    with codecs.open(filename, "w", encoding=encoding) as f:
        json.dump(data, f, ensure_ascii=False, indent=4, sort_keys=True)
727798
def _format_json(self, ans, q):
        
        params = {}
        try: params['indent'] = int(q.get('indent')[0])
        except: pass

        return json.dumps(ans, **params)+'\n'
1175555
def __write_json_file(path, values):
    """"""
    # Sort the keys to ensure ordering
    sort_order = ['name', 'switch', 'comment', 'value', 'flags']
    sorted_values = [
        OrderedDict(
            sorted(
                value.items(), key=lambda value: sort_order.index(value[0])))
        for value in values
    ]

    with open(path, 'w') as f:
        json.dump(sorted_values, f, indent=2, separators=(',', ': '))
1076738
def _write_json(filepath, data, kwargs):
    """"""
    with io_stl.open(filepath, 'w', encoding='utf8') as outfile:
        if 'indent' not in kwargs:
            kwargs['indent'] = 4
        if 'sort_keys' not in kwargs:
            kwargs['sort_keys'] = True
        if 'separators' not in kwargs:
            kwargs['separators'] = (',', ': ')
        if 'ensure_ascii' not in kwargs:
            kwargs['ensure_ascii'] = False
        str_ = json.dumps(data, **kwargs)
        outfile.write(to_unicode(str_))
    return data
512765
def publish_json(self, channel, obj):
        """"""
        return self.publish(channel, json.dumps(obj))
1269222
protected void writeJSON(final HttpServletResponse resp, final Object obj)
      throws IOException {
    writeJSON(resp, obj, false);
  }
677383
def to_json(data, pretty):
    
    if pretty:
        return json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
    return json.dumps(data)
670968
def write_json_file(self, path):
        
        with open(path, "w") as f:
            f.write(self.to_json())
924189
def toJson(self, data=None, pretty=False):
        """"""
        if data==None: data = self.attrs
        data = self.flatten(data) # don't send objects as str in json
        #if pretty:
        ret = json.dumps(data, indent=4, sort_keys=True)
        #self.inflate() # restore objects from json str data
        return ret
338374
def to_json(obj, pretty=False):
  
  sort_keys = False
  indent = None
  separators = (",", ":")

  if isinstance(pretty, tuple):
    sort_keys, indent, separators = pretty
  elif pretty is True:
    sort_keys = True
    indent = 2
    separators = (", ", ": ")

  return json.dumps(obj, sort_keys=sort_keys, indent=indent, separators=separators,
                    default=json_default)
824702
def json(self, dict=None, indent=None):
        
        if not dict:
            dict = self.dict()
        for key, value in dict.iteritems():
            if type(value) == datetime.datetime:
                dict[key] = value.strftime(conf.GOSCALE_ATOM_DATETIME_FORMAT)
        return simplejson.dumps(dict, indent=indent)
886759
public void writeJSON(JSONValue jc, JSONWriter jb, boolean writeClass)
            throws IOException {
        String key;
        Object value;
        jb.objectBegin();
        for (Map.Entry<String, Object> entry : objectMap.entrySet()) {
            key = entry.getKey();
            jb.objectItem(key);
            value = entry.getValue();
            if (value == null)
                jb.valueNull();
            else
                jc.writeValue(value, jb, writeClass);
        }
        jb.objectEnd();
    }
205739
def write_json_to_file(self, net_type, filename, indent='no-indent'):
    '''
    
    '''
    export_data.write_json_to_file(self, net_type, filename, indent)
362635
def write_json(template, file_name='../dxf.json.template'):
    
    with open(file_name, 'w') as f:
        json.dump(template, f, indent=4)
340520
def write_json_string(str)
      @context.write(trans)
      trans.write(@@kJSONStringDelimiter)
      str.split('').each do |ch|
        write_json_char(ch)
      end
      trans.write(@@kJSONStringDelimiter)
    end
579178
def json_dumps(self, obj):
        """"""
        return json.dumps(obj, sort_keys=True, indent=4, separators=(',', ': '))
486824
def tojson(val, indent=None):
    '''
    
    '''
    options = {'ensure_ascii': True}
    if indent is not None:
        options['indent'] = indent
    return (
        salt.utils.json.dumps(
            val, **options
        ).replace('<', '\\u003c')
         .replace('>', '\\u003e')
         .replace('&', '\\u0026')
         .replace("'", '\\u0027')
    )