{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d18900df-77a4-424c-afa6-ae34ca31d055",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import ast"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "2aff65d5-34bf-4f1c-abad-9343d1c53d4f",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def read_and_update_json(filename):\n",
    "    with open(filename, 'r') as file:\n",
    "        data = json.load(file)\n",
    "\n",
    "    # Convert colmap_im_id to integer for proper numeric sorting\n",
    "    sorted_frames = sorted(data[\"frames\"], key=lambda x: int(x[\"colmap_im_id\"]))\n",
    "\n",
    "    data[\"frames\"] = sorted_frames\n",
    "\n",
    "    # Write the modified data back to the JSON file\n",
    "    with open(filename, 'w') as file:\n",
    "        json.dump(data, file, indent=4)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5379a69b-721a-4aba-9c5e-bf006ada2866",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "628b2bc9-819c-4d19-a204-0060dae9fc34",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Replace 'your_file_path.json' with the path to your actual JSON file\n",
    "filename = 'transforms.json'\n",
    "read_and_update_json(filename)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9b10be8-a4eb-4b29-be52-e26da8bb5db1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "yt38",
   "language": "python",
   "name": "yt38"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
