The Load JSON feature lets you populate a road with many obstacles in a single operation rather than adding them one at a time through the Add Obstacles form. When you click the Load JSON button, the application opens a modal that accepts aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tutosrive/avl_tree_car_front/llms.txt
Use this file to discover all available pages before exploring further.
.json file, displays its contents in a preview textarea, and sends the parsed object to the backend when you confirm. Understanding the exact file structure is essential for creating files that the backend will accept without errors.
Purpose
A JSON import file describes two things: optional road configuration (primarily the total road width) and the list of obstacles to place on that road. The application reads the file client-side withFileReader, parses it as JSON, resets the backend AVL tree, and then POSTs the entire object to POST /avl/add/configs. On success the backend returns an array of assigned obstacle IDs that the client uses to build its in-memory Obstacle instances.
Top-Level Structure
The JSON object must have exactly two top-level keys.Road-level configuration settings applied before the obstacles are inserted.
An ordered array of obstacle objects. Each element becomes one node in the backend AVL tree.
configs Object
Sets the road width on the client side after a successful import by calling
road.setWidth(total_distance). Should be equal to or greater than the largest x coordinate in your obstacles array. The minimum recommended value is 500 (the default road width). If omitted, the road width remains at whatever was set when the road was created.obstacles Array
Each element of the obstacles array is an object describing a single road obstacle.
Horizontal pixel position of the obstacle on the road. Valid range: between 5 % of
total_distance and total_distance − 15. For a total_distance of 1500, the valid X range is approximately 75 to 1485.Vertical pixel position of the obstacle on the road. Valid range: 5 (minimum) to the road height (default
300).The obstacle type name as a lowercase string. The client uppercases the first character before sending to the backend (e.g.
"cone" becomes "Cone"). See the Valid Type Values table below for all accepted strings.Type Normalization
Before sending the JSON payload to the backend,LoadJSONController iterates the obstacles array and transforms each type string:
"cone" and "Cone" are therefore valid input values; the resulting backend value will always be "Cone".
Valid Type Values
JSON type value | Normalized (sent to backend) |
|---|---|
cone | Cone |
rock | Rock |
tree | Tree |
tire | Tire |
nail | Nail |
trunk | Trunk |
person | Person |
car | Car |
bicycle | Bicycle |
chair | Chair |
Full Example
API Endpoint
POST /avl/add/configs
The entire JSON object (including both configs and obstacles) is sent as the request body.
Request
Response (status 200)
HTTP-style status code.
200 indicates all obstacles were successfully inserted into the AVL tree.Human-readable confirmation message displayed in a success toast.
Array of backend-assigned obstacle IDs. The array length equals the number of objects in the
obstacles input array and the order is preserved — data[0] is the ID for obstacles[0], data[1] for obstacles[1], and so on. These IDs are used to construct the client-side Obstacle instances and are stored on this.road.Reset Behavior
The reset sequence is:avlCtrl.service.emit_reset_avl()→ backend clears the tree.POST /avl/add/configs→ backend inserts all JSON obstacles and returns their IDs.- Client builds
Obstacleinstances and callsroad.setObstacles(obstaclesList), replacing the previous obstacles array entirely. avlCtrl.getTree()→ backend emitsavl_tree_balanced→ D3.js re-renders the tree.
Notes on Client-Side Processing
After a successful response the controller calls#setObstaclesFromTextArea(req.data), which:
- Checks that
element.textLength >= 50; if the textarea content is shorter than 50 characters the method returns early and no obstacles are built. - Re-parses the textarea content as JSON.
- Iterates
json.obstaclesin order, pairing each entry with its assigned ID fromreq.data. - Uppercases the first character of each
typestring. - Constructs a
new Obstacle({ id, x, y, type, is_type_str: true })for each entry. Theis_type_str: trueflag tellsObstacle.format_values()to match the type by string name rather than numeric ID. - Calls
road.setObstacles(obstaclesList)to replace the road’s obstacle array with the newly built list.
The
id field in each constructed Obstacle comes from the backend response, not from the JSON file. Do not include an id key in your obstacle objects — it will be ignored.