Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
12 changes: 6 additions & 6 deletions UI/backend/json_error_to_english.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import re

# ---------------------------------------------------------------------------
# Humanfriendly explanations for common JSON parsing errors.
# These map fragments of pyjson5 error messages to clearer descriptions.
# Human-friendly explanations for common JSON parsing errors.
# These map fragments of json5 error messages to clearer descriptions.
# ---------------------------------------------------------------------------
ERROR_EXPLANATIONS = {
"identifierstart": "Invalid start of identifier: object keys must begin with a quote `\"`.",
Expand All @@ -25,12 +25,12 @@

def _friendly_message(msg: str) -> str:
"""
Convert a raw pyjson5 error message into a more readable explanation.
Convert a raw json5 error message into a more readable explanation.

Parameters
----------
msg : str
The raw error message from pyjson5.
The raw error message from json5.

Returns
-------
Expand Down Expand Up @@ -64,7 +64,7 @@ def pretty_json_error(input_string: str, error: Exception):
input_string : str
The original JSON text the user attempted to parse.
error : Exception
The exception raised by pyjson5.
The exception raised by json5.

Returns
-------
Expand All @@ -75,7 +75,7 @@ def pretty_json_error(input_string: str, error: Exception):

# -----------------------------------------------------------------------
# Extract character position from the exception.
# pyjson5 sometimes exposes `.pos`, but not always, so we fall back to
# json5 sometimes exposes `.pos`, but not always, so we fall back to
# regex extraction from the message.
# -----------------------------------------------------------------------
pos = getattr(error, "pos", None)
Expand Down
12 changes: 5 additions & 7 deletions UI/backend/json_validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fastapi import APIRouter
import pyjson5
import json5
from pydantic import BaseModel
from .json_error_to_english import pretty_json_error

Expand All @@ -24,7 +24,7 @@ def room(payload: InputModel):
Validate room JSON submitted by the frontend.

This endpoint performs two layers of validation:
1. Parse the input using pyjson5 (allows comments, trailing commas, etc.)
1. Parse the input using json5 (allows comments, trailing commas, etc.)

Returns
-------
Expand All @@ -36,7 +36,7 @@ def room(payload: InputModel):

# Step 1: JSON parsing (with helpful error messages)
try:
data = pyjson5.loads(input_string)
data = json5.loads(input_string)
return {"success": True}
except Exception as e:
return {
Expand All @@ -45,14 +45,13 @@ def room(payload: InputModel):
}



@router.post("/wind")
def wind(payload: InputModel):
"""
Validate wind JSON submitted by the frontend.

Follows the same two‑stage validation process as /room:
1. Parse JSON using pyjson5
1. Parse JSON using json5

Returns
-------
Expand All @@ -64,11 +63,10 @@ def wind(payload: InputModel):

# Step 1: JSON parsing
try:
data = pyjson5.loads(input_string)
data = json5.loads(input_string)
return {"success": True}
except Exception as e:
return {
"success": False,
"message": pretty_json_error(input_string, e)
}

2 changes: 0 additions & 2 deletions UI/backend/transport_paths_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class InputModel(BaseModel):
apertures: List[InputAperture]




@router.post("/paths")
def paths(payload: InputModel):
"""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.