Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/fast-json-data

Fast JSON data disk read/write.
https://github.com/stagas/fast-json-data

Last synced: 14 days ago
JSON representation

Fast JSON data disk read/write.

Awesome Lists containing this project

README

        


fast-json-data

Fast JSON data disk read/write.



npm i fast-json-data

pnpm add fast-json-data

yarn add fast-json-data

Efficiently read and write well-formed JSON data to the disk. About x1.5-2 times as fast as JSON.parse/stringify.

```ts
import { Literal, parse, stringify } from 'fast-json-data'

const schema = [[Literal, [
'_id',
'_rev',
'name',
'homepage',
['versions', ['*', [
'name',
'gitHead',
['os', [Literal]],
['cpu', [Literal]],
['engines', ['*']],
['dist', [
'shasum',
'tarball',
'unpackedSize',
]],
['dependencies', [
'*',
]],
]]],

['time', ['*']],
]]]

...

// packumentCache is a Map

await fsp.writeFile(
options.packumentCachePath,
stringify(schema, [...packumentCache]),
'utf-8'
)

...

json = parse(schema, await fsp.readFile(options.packumentCachePath, 'utf-8'))
```

## API

# Literal  =  ... src/fast-json-data.ts#L1

# parse(schema, input) src/fast-json-data.ts#L62

    # schema


      any

    # input

      string


    parse(schema, input)  =>


      any

# parseLines(schema, input) src/fast-json-data.ts#L66

parseLines(schema, input)  =>

    any
# stringify(schema, input) src/fast-json-data.ts#L3

    # schema


      any

    # input

      any


    stringify(schema, input)  =>


      string

## Contributing

[Fork](https://github.com/stagas/fast-json-data/fork) or [edit](https://github.dev/stagas/fast-json-data) and submit a PR.

All contributions are welcome!

## License

MIT © 2022 [stagas](https://github.com/stagas)