The `pickleparser` library provides a pure JavaScript and TypeScript implementation for parsing Python's pickle serialization format. It supports all pickle protocol versions from 0 to 5, allowing developers to deserialize Python objects directly within Node.js environments and web browsers. Currently stable at version 0.2.1, the project appears to have an active release cadence, frequently adding support for new opcodes and refining its API. A key differentiator is its full protocol support and its utility for converting pickle data to JSON, including a bundled `pickletojson` CLI tool, without relying on Python runtimes. It offers `ParserOptions` for customizing the unpickling process, making it flexible for various use cases.
npm install pickleparserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to read a Python pickle file from disk using Node.js, parse it with `pickleparser`, and log the resulting JavaScript object to the console, including a `BigInt` replacer for `JSON.stringify()`.
Refer to the latest documentation and examples for `Parser` class instantiation and method calls. The module now primarily uses named exports like `Parser`.
Provide a custom `replacer` function to `JSON.stringify()` to convert `BigInt`s to strings or another serializable format. For example: `JSON.stringify(obj, (key, value) => typeof value === 'bigint' ? value.toString() + 'n' : value)`.
Upgrade to `pickleparser@0.0.2-alpha.2` or newer immediately to ensure all known security fixes are applied and to benefit from the most stable and secure parsing logic.
**Never parse pickle files from untrusted or unverified sources.** Always treat parsed data as potentially hostile and implement robust validation and sanitization before using it within your application logic.
Modify your `JSON.stringify()` call to include a `replacer` function that converts `BigInt` values to strings or another serializable type: `JSON.stringify(obj, (key, value) => typeof value === 'bigint' ? value.toString() : value)`.
Ensure the input data is read in binary format and converted to the correct type. For Node.js, use `fs.readFileSync(filePath, null)` to get a `Buffer`. For browsers, use a `FileReader` to read as `ArrayBuffer` and convert to `Uint8Array`.
In browser applications, verify the library's `<script>` tag is correctly placed and loaded. In Node.js or module-based environments, use explicit ESM `import { Parser } from 'pickleparser';` or CJS `const { Parser } = require('pickleparser');`.No dependency data recorded yet.