code: def generate_json_package(folder, package_name, use_carla_materials):
      """Generate a .json file with all the maps it founds on the folder
      and subfolders. A map is a .fbx and a .xodr with the same name.
      """
      json_files = []
  
      # search for all .fbx and .xodr pair of files
      maps = []
      for root, _, filenames in os.walk(folder):
          files = fnmatch.filter(filenames, "*.xodr")
          for file_name in files:
              xodr = file_name[:-5]
              # check if exist the .fbx file
              if os.path.exists("%s/%s.fbx" % (root, xodr)):
                  maps.append(
                      [
                          os.path.relpath(root, folder),
                          xodr,
                          ["%s.fbx" % xodr],
                      ]
                  )
              else:
                  # check if exist the map by tiles
                  tiles = fnmatch.filter(filenames, "*_Tile_*.fbx")
                  if len(tiles) > 0:
                      maps.append(
                          [os.path.relpath(root, folder), xodr, tiles]
                      )
  
      # write the json
      if len(maps) > 0:
          # build all the maps in .json format
          json_maps = []
          for map_name in maps:
              path = map_name[0].replace("\\", "/")
              name = map_name[1]
              tiles = map_name[2]
              tiles = ["%s/%s" % (path, x) for x in tiles]
              map_dict = {
                  "name": name,
                  "xodr": "%s/%s.xodr" % (path, name),
                  "use_carla_materials": use_carla_materials,
              }
              # check for only one 'source' or map in 'tiles'
              if len(tiles) == 1:
                  map_dict["source"] = tiles[0]
              else:
                  map_dict["tile_size"] = 2000
                  map_dict["tiles"] = tiles
  
              # write
              json_maps.append(map_dict)
          # build and write the .json
          f = open("%s/%s.json" % (folder, package_name), "w")
          my_json = {"maps": json_maps, "props": []}
          serialized = json.dumps(my_json, sort_keys=False, indent=3)
          f.write(serialized)
          f.close()
          # add
          json_files.append([folder, "%s.json" % package_name])
  
      return json_files
  
imports: from __future__ import print_function
  import errno
  import fnmatch
  import glob
  import json
  import os
  import shutil
  import subprocess
  import sys
  import argparse
  import threading
  import copy
  import carla
label_desc: Use image node_id 3 for calling a global function with example usage: generate_json_package(folder, package_name, use_carla_materials) and returns: json_files