import { useMemo, useState } from "react" import jp from "jsonpath" import JsonTreeNode from "@/components/json-tree-node" /** * Home page component that displays the main landing content. */ export default function Home() { const initialData = { centre_id: "LON-01", location: "London", is_active: true, staff_members: [ { id: 101, name: "Alice", roles: ["Admin", "Manager"] }, { id: 102, name: "Bob", roles: ["Developer"] }, ], config: { colour_scheme: "Dark Mode", retention_days: 30, }, } const [jsonInput, setJsonInput] = useState(JSON.stringify(initialData, null, 2)) const [query, setQuery] = useState("$.staff_members[*].name") // 计算匹配结果 const result = useMemo(() => { try { const parsed = JSON.parse(jsonInput) const nodes = jp.nodes(parsed, query) return { parsed, matchedPaths: nodes.map((n) => jp.stringify(n.path)), error: null, } } catch (e) { return { parsed: null, matchedPaths: [], error: (e as Error).message } } }, [jsonInput, query]) return (

TypeScript JSONPath Explorer

Debug and visualises your JSONPath queries with real-time highlighting.

{/* 控制面板 */}
JSON Source