Support TypedArrays

Aperta
#626 1 commento 4 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@junaidkhan80121 ci sta già lavorando.

Dal 4/11/2026.

  • #913 di @junaidkhan80121 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript

Direzione di ricerca

Inizia leggendo index.js intorno al controllo Array.isArray citato nella issue e riproduci l’esempio Float32Array. Esamina come dovrebbero funzionare la compatibilità proposta dello schema e il comportamento di largeArrayMechanism; il lavoro è considerato completato quando i TypedArrays vengono serializzati correttamente per gli schemi compatibili senza modificare il comportamento degli array normali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature request
Prerequisites
  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested
🚀 Feature Proposal

fast-json-stringify does not work with TypedArray objects (Float32Array, etc.). Normally, using JSON.stringify to serialize a TypedArray results in writing it as an object (e.g., new Float32Array([0.1,0.2]) gets serialized as {"0":0.1,"1":0.2}). However, since fast-json-stringify uses a JSON Schema to guide its output, it can know that a given property is an array; it seems reasonable and consistent to allow it to serialize TypedArrays as well as regular arrays.

Proposed implementation:

  • The Array.isArray check could be broadened to also allow TypedArrays.
  • TypedArray can only hold (floating point or integer) numbers, so it would not work with many JSON Schemas. One option would be to only allow TypedArray if the JSON Schema is compatible with TypedArray (e.g., only number items); another option would be to allow it as is and then let individual elements fail validation.
  • If a TypedArray is in use, largeArrayMechanism is ignored (treated as default).
Motivation

Our application uses TypedArray for several purposes. This is fast internally but is noticeably slower to serialize. Using fast-json-stringify, locally patched to support TypedArray, is over 2.5x faster for a Float32Array of 4000 randomly generated numbers.

Example
const array = new Float32Array(new Array(4000).fill(1));

const stringify = fastJson({
  title: 'Example Schema',
  type: 'array',
  items: {
    type: 'number'
  }
})

console.log(stringify(array));
Lingua principale
JavaScript
Stelle
3.7k
Fork
245
Merge medio
3g 5h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di fastify/fast-json-stringify

Tutte le issue di fastify/fast-json-stringify

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.