title: How to build JSON from python script?
body: <p>I am new to JSON and I want to generate a JSON file from a python script</p>
  
  <p>For example:</p>
  
  <pre><code>#take input from the user
  
  num = int(input("Enter a number: "))
  
  # prime numbers are greater than 1
  
  if num &gt; 1:
  
  #check for factors
  
  for i in range(2,num):
      if (num % i) == 0:
          print(num,"is not a prime number")
          print(i,"times",num//i,"is",num)
          break
  else:
      print(num,"is a prime number")
  
  # if the input number is less than or equal to 1, it is not prime
  
  else: print(num,"is not a prime number")
  </code></pre>
  
  <p>For the above python script, how to generate a JSON file? Is there any tool or a software?</p>
  
  <p>I don't want to create a JSON file manually. The above code is just an example.</p>
  
  <p>I have a code for object detection and multiple input images. In each image the objects are same, but the location of the objects are different.</p>
  
  <p>inputImage: <a href="https://i.stack.imgur.com/git8P.jpg" rel="nofollow noreferrer">Trolley_Problem</a></p>
  
  <p>tramTemplate: <a href="https://i.stack.imgur.com/dMqta.jpg" rel="nofollow noreferrer">tram1</a></p>
  
  <p>UPDATE 1:</p>
  
  <pre><code>import numpy as np
  import cv2
  
  # Read the main image
  
  inputImage = cv2.imread("Trolley_Problem.jpg")
  
  # Convert it to grayscale
  
  inputImageGray = cv2.cvtColor(inputImage, cv2.COLOR_BGR2GRAY)
  
  # Read the templates
  
  tramTemplate = cv2.imread("tram1.jpg")
  
  # Convert the templates to grayscale
  
  tramTemplateGray = cv2.cvtColor(tramTemplate, cv2.COLOR_BGR2GRAY)
  
  #Store width and height of the templates in w and h
  
  h1,w1 = tramTemplateGray.shape
  
  # Perform match operations.
  
  tramResult = cv2.matchTemplate(inputImageGray,tramTemplateGray, cv2.TM_CCOEFF_NORMED)
  
  # Specify a threshold
  
  threshold = 0.75
  
  # Store the coordinates of matched area in a numpy array
  
  loc1 = np.where( tramResult &gt;= threshold)
  
  for pt in zip(*loc1[::-1]):
      cv2.rectangle(inputImage,pt, (pt[0] + w1, pt[1] + h1), (0,255,255), 1)
      cv2.putText(inputImage,"Tram Detected", (200,50), font, 0.5, 255)
  
  # Show the final result
  
  cv2.imwrite(r "Trolley_Problem_Result.jpg", inputImage)`
  </code></pre>
  
  <p>So, I have to generate JSON file for this object detection program.</p>
  
  <p>Thank you</p>