code: def rebalance_json(data_dir, data_json, num, prefix):
      data = []
      seg = 0
      with open(data_json, "r") as f:
          for line in f:
              data.append(json.loads(line))
  
      filename = data_json.split("/")[-1]
      fout_path = os.path.join(data_dir, prefix + "_" + filename)
  
      if len(data) >= num:
          selected_sample = np.random.choice(data, num, replace=False)
      else:
          selected_sample = np.random.choice(data, num, replace=True)
  
      with open(fout_path, "a") as fout:
          for i in selected_sample:
              seg += 1
              json.dump(i, fout)
              fout.write("\n")
              fout.flush()
  
      logging.info(f"Get {seg}/{num} to  {fout_path} from {data_json}")
      return fout_path
  
imports: import argparse
  import glob
  import json
  import logging
  import os
  import tarfile
  import urllib.request
  import librosa
  import numpy
  import soundfile
  from sklearn.model_selection import train_test_split
label_desc: Use image node_id 8 for calling a global function with example usage: rebalance_json(data_dir, data_json, num, prefix) and returns: fout_path