import json
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

def x2j(N):
	if N.startswith('https://') or N.startswith('http://'):
		getxml = requests.get(N, verify=False)
		xmltext = getxml.text
	else:
		xmltext = N
	multipart_data =MultipartEncoder(
		fields={'forceInNewWindow':'true',
				'xmlString':xmltext,
				'encoding':'UTF8',
				'attributePrefix':'@',
				'textPropertyName':'#text',
				'indentation':'THREE_SPACES',
				'braceStyle':'COLLAPSE'})
	r = requests.post('https://www.freeformatter.com/xml-to-json-converter.html', data=multipart_data,
			  headers={'Content-Type': multipart_data.content_type}, verify=False)
	return json.loads(r.text)