jsoncrack.com's json2go.js carries the highest activity risk — 5 hotspots to address

Two files dominate risk: json2go.js (jsonToGo and parseScope functions with CC 29–32, ND 8) and parser.ts (traverse and anonymous handlers with CC 11–16, activity_risk 13–14). Both show god-function and exit-heavy patterns.

Stephen Collins ·
oss typescript refactoring code-health

Antipatterns Detected

god_function 8 long_function 8 exit_heavy 7 complex_branching 2 deeply_nested 2

Top pattern: god_function

Key Points

What is a god_function and why does it matter in jsoncrack.com?

A god_function tries to do too much in one place. In jsoncrack.com, jsonToGo handles JSON parsing, type inference, and Go code generation all together, making it harder to test and maintain. Breaking it into smaller, focused functions reduces the surface area for bugs.

How do I reduce cyclomatic complexity in TypeScript?

Extract branching logic into separate helper functions or use a strategy/lookup pattern instead of nested if-else chains. In jsonToGo, splitting type-detection logic into a dedicated module would lower the complexity score and improve readability.

Is jsoncrack.com actively maintained?

Yes—the activity metrics show frequent commits touching json2go.js and parser.ts, which means bugs in these files will affect users quickly. This makes refactoring them a practical priority, not a future concern.

How do I reproduce this analysis?

Use the hotspots CLI against the AykutSarac/jsoncrack.com repository; the analysis targets the current main branch and weights findings by commit frequency over recent history.

What does activity-weighted risk mean?

Complexity × recent commit frequency—functions that are both hard to understand AND actively changing are the highest priority because they're touched often and carry higher odds of introducing bugs.

jsoncrack.com faces concentrated structural risk in its JSON-to-Go conversion layer and React parsing pipeline. Two functions — jsonToGo and parseScope in apps/www/src/lib/utils/json2go.js — carry activity_risk scores of 19.0 and 14.92 respectively, driven by cyclomatic complexity values of 32 and 29 combined with nesting depths of 8. Across 574 total functions, 12 are flagged as critical, with god-function and exit-heavy patterns dominating the top hotspots. This analysis focuses on the highest-risk real project code to help prioritize refactoring effort.

The table below ranks functions by activity-weighted risk — a score that multiplies structural complexity by recent commit frequency. A function that is both hard to understand (high cyclomatic complexity) and actively changing is a higher priority than one that is complex but untouched. CC = cyclomatic complexity (independent execution paths); ND = max nesting depth; FO = fan-out (distinct callees).

Top 5 Hotspots

FunctionFileRiskCCNDFO
jsonToGoapps/www/src/lib/utils/json2go.js19.032847
parseScopeapps/www/src/lib/utils/json2go.js14.929811
traversepackages/jsoncrack-react/src/parser.ts14.516315
<anonymous>packages/jsoncrack-react/src/parser.ts13.711316
<anonymous>packages/jsoncrack-react/src/JSONCrackComponent.tsx13.514222

Hotspot Analysis

jsonToGo — apps/www/src/lib/utils/json2go.js

jsonToGo (risk score 19.0, CC 32, ND 8, FO 47) translates JSON structures into Go type definitions — a logic-heavy conversion task. The cyclomatic complexity of 32 means 32 independent execution paths and 32 required test cases; nesting depth of 8 makes the code mentally taxing to reason through. Fan-out of 47 indicates this function calls broadly across the codebase, so changes here have a wide blast radius. The combination of high recent commit frequency and structural debt signals a function under active iteration that is simultaneously hard to modify safely.

Recommendation: Before refactoring, map the 47 outbound calls to identify which are essential vs. structural; extract the innermost nested blocks (those at ND 8) into named helper functions to reduce the max nesting depth to 4 or below. Add characterization tests for all 32 paths before making any changes, so regressions are caught immediately.

parseScope — apps/www/src/lib/utils/json2go.js

parseScope (risk score 14.9, CC 29, ND 8, FO 11) is a scope-parsing routine that shares the same file and structural debt profile as jsonToGo. CC 29 and ND 8 place it in the same high-risk category; although fan-out is lower (11 vs. 47), the deeply nested branching and god-function pattern mean this function is a candidate for decomposition. Recent commit activity indicates ongoing changes in an already-complex module.

Recommendation: Extract branches at nesting levels 5+ into separate named functions (e.g., validateScope, resolveType) to lower ND toward 4. Consider adding a state-machine or table-driven approach if parseScope is handling multiple distinct scope types — this can replace conditional branching with data-driven logic.

traverse — packages/jsoncrack-react/src/parser.ts

traverse (risk score 14.5, CC 16, ND 3, FO 15) is the React parser’s tree-traversal kernel. While ND 3 is reasonable, CC 16 combined with an exit-heavy pattern (multiple return paths) and high recent commit frequency means test coverage is fragile — each of 16 paths requires explicit coverage. High fan-out (15 distinct functions) couples this parser to many downstream handlers, so a subtle logic change here can trigger unexpected failures in dependent code.

Recommendation: Consolidate early-exit paths by using a guard-clause pattern at the function head; this reduces the mental load on readers and clarifies the happy path. Add integration tests that exercise the parser against representative JSON structures before modifying traverse logic.

Patterns Found

Antipatterns detected across the top functions in this snapshot:

PatternOccurrences
god_function8
long_function8
exit_heavy7
complex_branching2
deeply_nested2

These labels belong to two tiers — Tier 1 (structural): complex_branching, deeply_nested, exit_heavy, long_function, god_function. Tier 2 (relational/temporal): hub_function, cyclic_hub, middle_man, neighbor_risk, stale_complex, churn_magnet, shotgun_target, volatile_god.

Key Takeaways

  • jsonToGo and parseScope in json2go.js are both in the critical band with activity_risk >14 and CC >29; both sit at ND 8 (the cognitive breaking point). Extract deeply nested inner blocks into focused helper functions as the first refactoring step — this reduces nesting depth and opens the door to easier testing.
  • Eight functions across the codebase exhibit god-function patterns; jsonToGo’s FO 47 is the most extreme. Before modifying a god-function, map its outbound calls to understand ripple-effect risk; consider grouping related callees into a single coordinating function to lower fan-out.
  • Seven functions are exit-heavy, including traverse and two anonymous functions in parser.ts and JSONCrackComponent.tsx. Exit-heavy functions require exhaustive test coverage for each path. Adopt guard-clause patterns (early returns for invalid states) to clarify the intent and simplify path counting.

Reproduce This Analysis

git clone https://github.com/AykutSarac/jsoncrack.com
cd jsoncrack.com
git checkout e99288b4eff060dcd53428f2a3a5c2f28eecffa6
hotspots analyze . --mode snapshot

Hotspots highlights structural and activity risk — not “bad code.” Findings are a prioritization aid, not a bug predictor. Editorial policy →

Related Analyses