PageSourceSearch

https://talos.tools/assets/json-yaml-C8DzaRKH.js

js talos.tools collected 2026-10-06 17:53:48 UTC 8,804 bytes, 14 lines download raw bytes

1import{u as K,j as e}from"./vendor-query-BROoW_jZ.js";import{a as d}from"./vendor-router-DB8Iq42h.js";import{T as Q}from"./tool-layout-sidebar-BfPp0A7t.js";import{u as W,C as L,b as O,d as M,B as c,a as Y}from"./index-DUEDRU2t.js";import{T as I}from"./textarea-B1_SnVaJ.js";import{L as T}from"./label-9EYAsDEl.js";import{S as G,a as X,b as Z,c as _,d as f}from"./select-CoTwlEvd.js";import{T as ee,a as se,b as k}from"./tabs-CUd4DxO1.js";import{A as te,a as re}from"./alert-DR8T-cgP.js";import g from"./js-yaml-CO_3xtvD.js";import{C as ie}from"./circle-alert-Co8iOCFJ.js";import{F as N}from"./file-json-D-gS4w8t.js";import{F as y}from"./file-code--InR7nhx.js";import{C as E}from"./copy-C9OWDm-_.js";import{C as ae}from"./circle-check-big-MMSCo8DI.js";import{A as F}from"./arrow-right-left-BdMJrFu1.js";import"./page-head-Dc8X8fDS.js";import"./theme-toggle-CYJ0Zdz9.js";import"./use-favorites-B0QNNogk.js";import"./sponsor-button-BHCF4BzK.js";import"./heart-B4u0HA0q.js";import"./circle-check-Bk6XpyXj.js";import"./target-CAp_oSb-.js";import"./code-xml-CSSGWgOt.js";import"./circle-help-DgdU4BsY.js";import"./link-D3xms2eZ.js";import"./sheet-olztuKff.js";import"./index-BjrTZVyX.js";import"./index-BpjTTxnP.js";import"./index-DpcBFuQB.js";import"./scroll-area-BP6Y_hfQ.js";import"./index-DMsYNBze.js";import"./index-BdQq_4o_.js";import"./settings-Dq_8YxJ9.js";import"./panel-left-close-Diq_zBJU.js";import"./code-osZgrV1x.js";import"./panel-right-close-DMiz4Gyz.js";import"./index-DocI_qmi.js";import"./index-CAIXORah.js";import"./index-BBkT2x2P.js";import"./message-square-B8SGFu4f.js";import"./vendor-react-CHemKkfq.js";import"./index-y3zKCeUn.js";import"./chevron-down-DGOaJoNs.js";import"./check-BLcNYg_b.js";import"./chevron-up-WqDAXFCj.js";import"./index-vru6chB9.js";function es(){const[r,j]=d.useState("json-to-yaml"),[m,p]=d.useState(""),[u,h]=d.useState(""),[a,l]=d.useState(""),[C,i]=d.useState(null),[v,V]=d.useState("2"),{toast:n}=W(),{data:ne}=K({queryKey:["/api/tools/json-yaml"],queryFn:async()=>{const s=await fetch("/api/tools/json-yaml");return s.ok?s.json():null}}),S=s=>{if(!s.trim())return{valid:!1,error:"Input is empty"};try{return JSON.parse(s),{valid:!0,error:null}}catch(t){return{valid:!1,error:t instanceof Error?t.message:"Invalid JSON"}}},w=s=>{if(!s.trim())return{valid:!1,error:"Input is empty"};try{return g.load(s),{valid:!0,error:null}}catch(t){return{valid:!1,error:t instanceof Error?t.message:"Invalid YAML"}}},D=()=>{i(null);const s=S(m);if(!s.valid){i(s.error),n({title:"Validation Error",description:s.error,variant:"destructive"});return}try{const t=JSON.parse(m),o=g.dump(t,{indent:parseInt(v),lineWidth:-1,noRefs:!0});l(o),n({title:"Converted!",description:"JSON successfully converted to YAML"})}catch(t){const o=t instanceof Error?t.message:"Conversion failed";i(o),n({title:"Conversion Error",description:o,variant:"destructive"})}},U=()=>{i(null);const s=w(u);if(!s.valid){i(s.error),n({title:"Validation Error",description:s.error,variant:"destructive"});return}try{const t=g.load(u),o=JSON.stringify(t,null,parseInt(v));l(o),n({title:"Converted!",description:"YAML successfully converted to JSON"})}catch(t){const o=t instanceof Error?t.message:"Conversion failed";i(o),n({title:"Conversion Error",description:o,variant:"destructive"})}},B=()=>{r==="json-to-yaml"?D():U()},R=()=>{i(null);let s;r==="json-to-yaml"?s=S(m):s=w(u),s.valid?n({title:"Valid!",description:`Input is valid ${r==="json-to-yaml"?"JSON":"YAML"}`}):(i(s.error),n({title:"Validation Failed",description:s.error,variant:"destructive"}))},b=s=>{navigator.clipboard.writeText(s),n({title:"Copied!",description:"Content copied to clipboard"})},q=()=>{p(""),h(""),l(""),i(null)},z=()=>{a&&(r==="json-to-yaml"?(j("yaml-to-json"),h(a),p(""),l("")):(j("json-to-yaml"),p(a),h(""),l("")))},H=()=>{const s=JSON.stringify({name:"John Doe",age:30,email:"[email protected]",address:{street:"123 Main St",city:"New York",country:"USA"},hobbies:["reading","coding","hiking"],active:!0},null,2);r==="json-to-yaml"?p(s):h(`name: John Doe
2age: 30
3email: [email protected]
4address:
5  street: 123 Main St
6  city: New York
7  country: USA
8hobbies:
9  - reading
10  - coding
11  - hiking
12active: true`),i(null),l("")},x=r==="json-to-yaml"?m:u,A=r==="json-to-yaml"?"JSON":"YAML",J=r==="json-to-yaml"?"YAML":"JSON",P=e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{children:"Direction"}),e.jsx(ee,{value:r,onValueChange:s=>j(s),children:e.jsxs(se,{className:"grid w-full grid-cols-2",children:[e.jsxs(k,{value:"json-to-yaml",children:[e.jsx(N,{className:"mr-2 h-4 w-4"}),"JSON → YAML"]}),e.jsxs(k,{value:"yaml-to-json",children:[e.jsx(y,{className:"mr-2 h-4 w-4"}),"YAML → JSON"]})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"indent",children:"Indentation"}),e.jsxs(G,{value:v,onValueChange:V,children:[e.jsx(X,{id:"indent",children:e.jsx(Z,{})}),e.jsxs(_,{children:[e.jsx(f,{value:"2",children:"2 spaces"}
12),e.jsx(f,{value:"3",children:"3 spaces"}),e.jsx(f,{value:"4",children:"4 spaces"})]})]})]}),e.jsxs("div",{className:"space-y-2 pt-2 border-t",children:[e.jsxs(c,{onClick:B,className:"w-full",children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"Convert"]}),e.jsx(c,{onClick:R,variant:"outline",className:"w-full",children:"Validate"}),e.jsx(c,{onClick:H,variant:"outline",className:"w-full",children:"Load Sample"}),e.jsx(c,{onClick:z,variant:"outline",className:"w-full",disabled:!a,children:"Swap"}),e.jsx(c,{onClick:q,variant:"outline",className:"w-full",children:"Clear All"})]})]}),$=e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold mb-3 text-sm",children:"About JSON & YAML"}),e.jsxs("div",{className:"space-y-3 text-xs",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"JSON:"}),e.jsxs("ul",{className:"mt-1 space-y-1 text-muted-foreground",children:[e.jsx("li",{children:"• Lightweight data format"}),e.jsx("li",{children:"• Used in APIs"}),e.jsx("li",{children:"• Language-independent"})]})]}),e.jsxs("div",{children:[e.jsx("strong",{children:"YAML:"}),e.jsxs("ul",{className:"mt-1 space-y-1 text-muted-foreground",children:[e.jsx("li",{children:"• Human-readable"}),e.jsx("li",{children:"• Superset of JSON"}),e.jsx("li",{children:"• Used in configs"})]})]})]})]}),e.jsxs("div",{className:"pt-4 border-t",children:[e.jsx("h3",{className:"font-semibold mb-2 text-sm",children:"Use Cases"}),e.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[e.jsx("div",{children:"• Migrate configurations"}),e.jsx("div",{children:"• Format preferences"}),e.jsx("div",{children:"• Tool compatibility"})]})]})]});return e.jsxs(Q,{title:"JSON ↔ YAML Converter",description:"Convert between JSON and YAML formats with validation, syntax highlighting, and configurable indentation.",controlsContent:P,codeContent:$,defaultCodeOpen:!1,children:[C&&e.jsxs(te,{variant:"destructive",children:[e.jsx(ie,{className:"h-4 w-4"}),e.jsx(re,{children:C})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(L,{children:[e.jsx(O,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(M,{className:"flex items-center gap-2",children:[r==="json-to-yaml"?e.jsx(N,{className:"h-5 w-5"}):e.jsx(y,{className:"h-5 w-5"}),"Input (",A,")"]}),x&&e.jsx(c,{variant:"ghost",size:"sm",onClick:()=>b(x),children:e.jsx(E,{className:"h-4 w-4"})})]})}),e.jsxs(Y,{children:[e.jsx(I,{value:r==="json-to-yaml"?m:u,onChange:s=>{r==="json-to-yaml"?p(s.target.value):h(s.target.value),i(null),l("")},placeholder:`Paste your ${A} here...`,rows:20,className:"font-mono text-sm"}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[x.split(`
13`).length," lines, ",x.length," characters"]})]})]}),e.jsxs(L,{children:[e.jsx(O,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(M,{className:"flex items-center gap-2",children:[r==="json-to-yaml"?e.jsx(y,{className:"h-5 w-5"}):e.jsx(N,{className:"h-5 w-5"}),"Output (",J,")"]}),a&&e.jsx(c,{variant:"ghost",size:"sm",onClick:()=>b(a),children:e.jsx(E,{className:"h-4 w-4"})})]})}),e.jsx(Y,{children:a?e.jsxs(e.Fragment,{children:[e.jsx(I,{value:a,readOnly:!0,rows:20,className:"font-mono text-sm"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(ae,{className:"h-3 w-3 text-green-600"}),a.split(`
14`).length," lines, ",a.length," characters"]})]}):e.jsx("div",{className:"flex items-center justify-center h-[480px] text-muted-foreground",children:e.jsxs("div",{className:"text-center",children:[e.jsx(F,{className:"mx-auto h-12 w-12 mb-4 opacity-20"}),e.jsxs("p",{children:["Converted ",J," will appear here"]})]})})})]})]})]})}export{es as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.