code: def save_json_to_file(i):
      
  
      fn=i['json_file']
  
      if i.get('safe','')=='yes':
         d=i['dict']
  
         sd={}
  
         # Check main unprintable keys
         for k in d:
             try:
                json.dumps(d[k])
             except Exception as e: 
                pass
             else:
                sd[k]=d[k]
  
         i['dict']=sd
  
      r=dumps_json(i)
      if r['return']>0: return r
      s=r['string'].replace('\r','')+'\n'
  
      return save_text_file({'text_file':fn, 'string':s})
docs: Input:  {
                json_file    - file name
                dict         - dict to save
                (sort_keys)  - if 'yes', sort keys
                (safe)       - if 'yes', ignore non-JSON values (only for Debugging - changes original dict!)
              }
  
      Output: {
                return       - return code =  0, if successful
                                           >  0, if error
                (error)      - error text if return > 0
              }