title: Save json to a file in Azure Data Lake Storage Gen 2
body: <p>In Databricks, using Python, I am making a get request, using the requests library and the response is a json.</p>
  <p>Here is an example of the get request:</p>
  <pre><code>json_data = requests.get(&quot;https://prod-noblehire-api-000001.appspot.com/job?&quot;).json()
  </code></pre>
  <p>I would like to save the json_data variable as a file in Azure Data Lake Storage. I don't want to read it into Pyspark/Pandas DataFrame first and then save.</p>
  <p>If I was saving it to a local folder on my computer, I would have used the following code:</p>
  <pre><code>j = json.dumps(json_data)
  with open(&quot;MyJsonFile.json&quot;, &quot;w&quot;) as f:
      f.write(j)
      f.close()
  </code></pre>
  <p>However, since I would like to save it in Azure Data Lake Storage, I should be using the following, according to Microsoft's documentation:</p>
  <pre><code>def upload_file_to_directory():
      try:
  
          file_system_client = service_client.get_file_system_client(file_system=&quot;my-file-system&quot;)
  
          directory_client = file_system_client.get_directory_client(&quot;my-directory&quot;)
          
          file_client = directory_client.create_file(&quot;uploaded-file.txt&quot;)
          local_file = open(&quot;C:\\file-to-upload.txt&quot;,'r')
  
          file_contents = local_file.read()
  
          file_client.append_data(data=file_contents, offset=0, length=len(file_contents))
  
          file_client.flush_data(len(file_contents))
  
      except Exception as e:
        print(e)
  </code></pre>
  <p>How can I combine both pieces of code to save the variable as a file in ADLS?
  Also, is there a better way to do that?</p>