Registry / serialization / rdotjson

rdotjson

JSON →
library2.0.0jsnpmunverified

rdotjson is a Node.js library dedicated to parsing Android String Resource XML files (e.g., `strings.xml`) into a structured JavaScript object. It mirrors Android's `R` class access patterns, organizing resources under keys like `R.string`, `R.array`, `R.bool`, `R.color`, `R.dimen`, and `R.integer`. The library supports conversion of these resources into native JavaScript primitives or an object-wrapped format via `objectMode`. The current stable version is 2.0.0, and it maintains an active release cadence, as indicated by ongoing GitHub activity. Its key differentiators include extensive configuration options for handling XML comments, excluding specific keys with wildcards, preserving raw XML, and offering integrated formatters for JSON and CSV output. A robust command-line interface is also provided for direct file processing, making it suitable for build pipelines. It is designed for Node.js environments running version 18.17 or newer.

npm install rdotjson
INSTALL
IMPORT
SIG · RDOTJSON
R
rdotjson
serializationjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

rdotjson
import rdotjson from 'rdotjson';
import { rdotjson } from 'rdotjson';
The primary `rdotjson` parser function is a default export. Using named import will result in `TypeError`.
rdotjson
const rdotjson = require('rdotjson');
CommonJS `require` for Node.js environments where ESM is not used or supported.
rdotjson.format
import rdotjson from 'rdotjson'; const jsonFormatter = rdotjson.format('json');
import { format } from 'rdotjson';
Formatters (`json`, `csv`) are exposed as properties of the default exported `rdotjson` function, not as named exports.

Demonstrates parsing an Android `strings.xml` file, accessing parsed values, and using the JSON formatter. Includes setup and teardown for a runnable example.

import { promises as fs } from "fs"; import rdotjson from "rdotjson"; import path from 'path'; // Create a dummy strings.xml for demonstration const xmlContent = ` <resources> <string name="app_name">MyAwesomeApp</string> <string name="action_settings">Settings</string> <bool name="feature_enabled">true</bool> <integer name="max_items">10</integer> <string-array name="planets"> <item>Mercury</item> <item>Venus</item> <item>Earth</item> </string-array> </resources> `; const xmlPath = path.join(process.cwd(), 'strings.xml'); await fs.writeFile(xmlPath, xmlContent); async function parseAndroidResources() { try { const xml = await fs.readFile(xmlPath, 'utf8'); const R = await rdotjson(xml, { comment: 'pre' }); console.log(`App Name: ${R.string.app_name}`); // Expected: MyAwesomeApp console.log(`Feature Enabled: ${R.bool.feature_enabled}`); // Expected: true console.log(`Max Items: ${R.integer.max_items}`); // Expected: 10 console.log(`First Planet: ${R.array.planets[0]}`); // Expected: Mercury const jsonFormatter = rdotjson.format('json'); const jsonOutput = jsonFormatter(R, { space: 2 }); console.log('\nJSON Output:\n', jsonOutput); } catch (error) { console.error('Error parsing resources:', error); } finally { // Clean up the dummy file await fs.unlink(xmlPath); } } parseAndroidResources();
rdotjson --version
Debug
Known issues
breakingAs `rdotjson` is an ESM-first package since version 2.x, `require()` syntax for the default export (`rdotjson`) might not work directly in pure ESM projects without specific configuration (e.g., dual-packaging or bundler setup).
fix
Prefer `import rdotjson from 'rdotjson';` for ESM projects. For CommonJS, `const rdotjson = require('rdotjson');` is still supported, but ensure your Node.js version is compatible.
affects: >=2.0.0
gotchaUsing `objectMode: true` in the options will change the access pattern for parsed values. Instead of receiving primitive types (string, boolean, number), values will be wrapped in an object `{ value: T }`.
fix
When `objectMode` is enabled, access values via `.value` (e.g., `R.string.app_name.value`). If `objectMode` is not used, access directly (e.g., `R.string.app_name`).
affects: >=1.0.0
gotchaThe package explicitly requires Node.js version 18.17 or higher. Using it with older Node.js versions may lead to unexpected behavior or runtime errors due to incompatible features or APIs.
fix
Ensure your Node.js environment is updated to version 18.17 or newer before using `rdotjson`.
affects: >=1.0.0
gotchaThe various `comment` options (`'pre'`, `'post'`, `'right'`) are mutually exclusive in terms of how comments are handled. Specifying multiple might lead to only one being effective or unpredictable results, and they can significantly alter the output structure.
fix
Carefully review the documentation for each `comment` option and choose only one that fits your desired output format. Test the output to ensure comments are parsed as expected.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: rdotjson is not a function
Attempting to use `import { rdotjson } from 'rdotjson';` when `rdotjson` is a default export.
fix
Change the import statement to `import rdotjson from 'rdotjson';` for ESM or `const rdotjson = require('rdotjson');` for CommonJS.
Error: ENOENT: no such file or directory, open 'strings.xml'
The input XML file specified (e.g., `strings.xml`) does not exist at the provided path.
fix
Verify the file path is correct and accessible. Ensure the file actually exists on the filesystem where the Node.js process is running.
Error: XML parsing error: ... (e.g., 'Non-whitespace content after document element')
The input XML content is malformed or invalid according to XML standards, preventing successful parsing.
fix
Inspect the `strings.xml` content for syntax errors, unclosed tags, incorrect encoding, or extraneous characters. Use an XML validator if necessary.
TypeError: Cannot read properties of undefined (reading 'app_name')
Attempting to access a resource (e.g., `R.string.app_name`) that either doesn't exist in the parsed XML, or the `objectMode` option is active but the value is being accessed directly.
fix
Verify that the resource name matches exactly what is in the XML. If `objectMode: true` is used, access the value via `.value` (e.g., `R.string.app_name.value`). Also, check if the resource type (e.g., `string`) actually contains the key.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
Resources
rdotjson — npm install rdotjson · libregistry