croct-tech / croct-tech/json-pointer-js

Add support for traversing native `Map` objects like objects

Open
#96 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
3
Forks
0
PR merge metrics
No merged PRs in 30d

Description

✨ Feature request

JSON pointers should traverse native Map objects like plain and objects.

Motivation

Plain objects are inefficient and ill advised when dealing with large number of keys or when handling dynamic, possibly untrusted, keys.

To allow an application to traverse a path using keys provided by the user requires a lot of care and consideration to create an appropriate object.

Example

The API would remain the same, but now also support maps.

const map = new Map([
  ['foo', 'bar']
]);

JsonPointer.parse('/foo').get(map)
// => 'bar'
Alternatives

The safe and correct alternative to handle user-provided keys is to construct a prototype-free object using Object.create(null) and populating it iteratively. Besides inconvenient and unergonomic, such operation is linear at best and linearithmic at worst due to how the representation of plain objects are optimized to have few, statically known, unchanging keys.

Additional context

https://www.builder.io/blog/maps

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests; first locate the JSON Pointer traversal entry point and existing object-traversal tests. Use the Map example as the starting case, then verify that JsonPointer.parse('/foo').get(map) returns 'bar' while the existing API remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.