{"name":"jsonrequest.nu","source":"$ `stdlib/ext/http.nu`\n$ `stdlib/ext/json.nu`\n\n// Helper to print a JSON‑parsing error\n@ show_parse_err s label JsonError e → v {\n    ( nurl_print label )\n    ( nurl_print ( parse_err_msg # ParseErr . e kind ) )\n    ( nurl_print `\\n` )\n}\n\n// Helper to print an HTTP error\n@ show_http_err s label HttpErr e → v {\n    ( nurl_print label )\n    ( nurl_print ( http_err_name # HttpErr e ) )\n    ( nurl_print `\\n` )\n}\n\n// Entry point – called as: json_request_parser \"<url>\"\n@ main → i {\n    // Ensure we have a URL argument\n    : i argc ( nurl_argv_count )\n    ? <= argc 1 {\n        ( nurl_print `Usage: json_request_parser <url>\\n` )\n        ^ 1\n    } {}\n\n    // Get the URL string from the command line\n    : s url ( nurl_argv_get 1 )\n\n    // Perform a GET request (Result<Response, HttpErr>)\n    : !Response HttpErr r ( http_get url )\n    ?? r {\n        T resp → {\n            // Extract the response body as a string\n            : s body ( http_body_str resp )\n\n            // Parse the body as JSON (Result<Json, ParseErr>)\n            : !Json JsonError j ( json_parse body )\n            ?? j {\n                T obj → {\n                    // Pretty‑print the JSON object\n                    : String pretty ( json_pretty obj )\n                    ( nurl_print ( string_data pretty ) )\n                    ( nurl_print `\\n` )\n                    ( string_free pretty )\n                    ( json_free obj )\n                }\n                F e → ( show_parse_err `JSON parse error: ` # JsonError e )\n            }\n\n            ( response_free resp )\n        }\n        F e → ( show_http_err `HTTP error: ` # HttpErr e )\n    }\n\n    ^ 0\n}\n","bytes":1658}