text: user285: How do I parse the json file from ontology output.
  My file json file
  jdata <- read_json("analysis.json", simplifyVector = TRUE)
  
  I want to convert it into a data.frame format. I can able to take the GO term and respective p value etc. But I would like to know the genes that are getting part of the enriched list which is under the upload_1 for example under DNA Replication there are 33 terms but 8 are from my input. So my objective is to get the 8 gene so on and so forth.
  So I would like to see a data.frame where I want to have GO term in the first column gene mapped into the term would be second i.e upload_[#] third one fold enrichment and last one p value.
  This is how i would like to see this one is the text output in the column upload_1 (450) instead of that number i would like to see then gene names which are present in the json file.
  Some progress here is my code
  l <- fromJSON("analysis.json")
  
  m <- lapply(
    l[[1]]$result, 
    function(x) c(x$input_list$mapped_id_list['mapped_id'], x$term['id'],x$input_list['pValue'],x$term['label'])
  )
  m <- do.call(rbind, m)
  
  output:
  mapped_id     id           pValue       label                       
  [1,] Character,8   "GO:0006270" 0.007540801  "DNA replication initiation"
  [2,] Character,388 "GO:0009987" 3.232843e-10 "cellular process"          
  
  Right now I can parse out first two row.
  Things I would like to append to the code is
  
  I would like to do for all the terms
  The first column where i am trying to get all the genes now it is coming as character while number suggests gene present. That I wont need probably since i need only gene names which is being shown as character now.
  
  dput(head(b))
      structure(list(`GO biological process complete` = c("DNA replication initiation (GO:0006270)", 
      "regulation of blood coagulation (GO:0030193)", "regulation of hemostasis (GO:1900046)", 
      "regulation of coagulation (GO:0050818)", "platelet degranulation (GO:0002576)", 
      "cell cycle G1/S phase transition (GO:0044843)"), `upload_1 (450)` = c(8, 
      13, 13, 13, 16, 15), `upload_1 (fold Enrichment)` = c(11.23, 
      7.09, 7, 6.62, 5.75, 5.35), `upload_1 (P-value)` = c(0.00754, 
      0.000627, 0.000716, 0.00135, 0.000347, 0.00228)), row.names = c(NA, 
      -6L), class = c("tbl_df", "tbl", "data.frame"))
  
  Any suggestion or help would be really appreciated.
  
  
  user4282: I don't know how to do that in R but I think this is what you want:
  I used http://json2table.com for view the data structure of the JSON file, then I used json_normalize to normalize the JSON data into a flat table using the key [result] to a list of DataFrames for each index in the JSON file. Then, I concatenated the list of DataFrames in a single one with df.concat()
  import json
  import pandas as pd
  
  with open('analysis.json') as f:
      d = json.load(f)
  
  dfs = []
  for x, y in enumerate(d):
      data = pd.json_normalize(d[x]['result'])
      dfs.append(data)
  
  df = pd.concat(dfs, ignore_index=True)
  
  df.to_csv('analysis.csv', index=False)
  
  
original_text: 285: <p>How do I parse the json file from ontology output.
  My file <a href="https://drive.google.com/file/d/16_eL_2ec7anSnJ8i38KJPYtF2x7ydKX6/view?usp=sharing" rel="nofollow noreferrer">json file</a></p>
  <pre><code>jdata &lt;- read_json(&quot;analysis.json&quot;, simplifyVector = TRUE)
  </code></pre>
  <p>I want to convert it into a <code>data.frame</code> format. I can able to take the GO term and respective p value etc. But I would like to know the genes that are getting part of the enriched list which is under the upload_1 for example under DNA Replication there are 33 terms but 8 are from my input. So my objective is to get the 8 gene so on and so forth.</p>
  <p>So I would like to see a <code>data.frame</code> where I want to have GO term in the first column gene mapped into the term would be second i.e upload_[#] third one fold enrichment and last one p value.</p>
  <p>This is how i would like to see this one is the text output in the column <code>upload_1 (450)</code> instead of that number i would like to see then gene names which are present in the json file.</p>
  <p>Some progress here is my code</p>
  <pre><code>l &lt;- fromJSON(&quot;analysis.json&quot;)
  
  m &lt;- lapply(
    l[[1]]<span class="math-container">$result, 
    function(x) c(x$</span>input_list<span class="math-container">$mapped_id_list['mapped_id'], x$</span>term['id'],x<span class="math-container">$input_list['pValue'],x$</span>term['label'])
  )
  m &lt;- do.call(rbind, m)
  </code></pre>
  <p>output:</p>
  <pre><code>mapped_id     id           pValue       label                       
  [1,] Character,8   &quot;GO:0006270&quot; 0.007540801  &quot;DNA replication initiation&quot;
  [2,] Character,388 &quot;GO:0009987&quot; 3.232843e-10 &quot;cellular process&quot;          
  </code></pre>
  <p>Right now I can parse out first two row.</p>
  <p>Things I would like to append to the code is</p>
  <ul>
  <li>I would like to do for all the terms</li>
  <li>The first column where i am trying to get all the genes now it is coming as character while number suggests gene present. That I wont need probably since i need only gene names which is being shown as character now.</li>
  </ul>
  <pre class="lang-r prettyprint-override"><code>dput(head(b))
      structure(list(`GO biological process complete` = c(&quot;DNA replication initiation (GO:0006270)&quot;, 
      &quot;regulation of blood coagulation (GO:0030193)&quot;, &quot;regulation of hemostasis (GO:1900046)&quot;, 
      &quot;regulation of coagulation (GO:0050818)&quot;, &quot;platelet degranulation (GO:0002576)&quot;, 
      &quot;cell cycle G1/S phase transition (GO:0044843)&quot;), `upload_1 (450)` = c(8, 
      13, 13, 13, 16, 15), `upload_1 (fold Enrichment)` = c(11.23, 
      7.09, 7, 6.62, 5.75, 5.35), `upload_1 (P-value)` = c(0.00754, 
      0.000627, 0.000716, 0.00135, 0.000347, 0.00228)), row.names = c(NA, 
      -6L), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;))
  </code></pre>
  <p>Any suggestion or help would be really appreciated.</p>
  <p><a href="https://i.stack.imgur.com/6rKke.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6rKke.png" alt="pathway" /></a></p>
   4282: <p>I don't know how to do that in R but I think this is what you want:</p>
  <p>I used <a href="http://json2table.com" rel="nofollow noreferrer">http://json2table.com</a> for view the data structure of the JSON file, then I used <code>json_normalize</code> to normalize the JSON data into a flat table using the key <code>[result]</code> to a list of DataFrames for each index in the JSON file. Then, I concatenated the list of DataFrames in a single one with <code>df.concat()</code></p>
  <pre><code>import json
  import pandas as pd
  
  with open('analysis.json') as f:
      d = json.load(f)
  
  dfs = []
  for x, y in enumerate(d):
      data = pd.json_normalize(d[x]['result'])
      dfs.append(data)
  
  df = pd.concat(dfs, ignore_index=True)
  
  df.to_csv('analysis.csv', index=False)
  </code></pre>
  