Monu Tools

JSON σε TypeScript

Δημιουργήστε διεπαφές TypeScript από ένα δείγμα JSON, με ένθετους τύπους, πίνακες και προαιρετικά πεδία. Εκτελείται στο πρόγραμμα περιήγησής σας.

Πώς να χρησιμοποιήσετε το JSON σε TS

  1. 01

    Επικολλήστε ένα αντικείμενο ή πίνακα JSON.

  2. 02

    Προαιρετικά ορίστε το όνομα της ριζικής διεπαφής.

  3. 03

    Αντιγράψτε τις παραγόμενες διεπαφές TypeScript.

What the generator does

This is a JSON to TypeScript generator that infers a set of interfaces from an example JSON object or array, so you can paste an API response and get ready-to-use types instead of writing them by hand.

It is a big time-saver when you are consuming an API or a config file: paste a response, optionally name the root interface, and copy clean TypeScript straight into your code.

Generation runs entirely in your browser, so your data never leaves your device, which matters when the sample contains real values.

How it handles real-world shapes

It handles real-world shapes: nested objects become their own named interfaces referenced from the parent, arrays of objects are merged into one interface, and union types are produced where values vary.

Optional fields across mixed arrays

When the objects in an array do not all have the same keys, the keys missing from some elements are marked optional with a question mark, which matches how the data actually behaves and keeps the types honest.

It infers, it does not enforce a schema

One important point: it infers a shape from the single sample you give it, rather than enforcing a schema. If a field is sometimes null or absent in real data but not in your sample, the generated type will not know that, so use a representative example.

Συχνές ερωτήσεις

Πώς χειρίζονται τα ένθετα αντικείμενα;

Κάθε ένθετο αντικείμενο γίνεται η δική του ονομασμένη διεπαφή, αναφερόμενη από τον γονέα της, οπότε το αποτέλεσμα είναι καθαρό και επαναχρησιμοποιήσιμο.

Τι γίνεται με πίνακες διαφορετικών σχημάτων;

Πίνακες αντικειμένων συγχωνεύονται σε μία διεπαφή, και κλειδιά που λείπουν από κάποια στοιχεία σημειώνονται ως προαιρετικά. Πίνακες μικτών πρωτογενών τιμών αποκτούν έναν τύπο στοιχείου ένωσης.

Ανεβαίνει το JSON μου κάπου;

Όχι. Οι τύποι δημιουργούνται εξ ολοκλήρου στο πρόγραμμα περιήγησής σας, οπότε τα δεδομένα σας δεν φεύγουν ποτέ από τη συσκευή σας.

Πηγές

Ενσωματώστε αυτό το εργαλείο

Προσθέστε αυτό το εργαλείο στον δικό σας ιστότοπο. Αντιγράψτε το παρακάτω απόσπασμα, ενημερώνεται αυτόματα.

<iframe src="https://monu.tools/embed/el/json-to-typescript" width="100%" height="640" style="border:1px solid #e5e5e5;border-radius:12px;max-width:680px" loading="lazy" title="Monu Tools"></iframe>

Σχετικά εργαλεία