Giter Club home page Giter Club logo

json8's Introduction

json8's People

Contributors

bastianqjw avatar cha0s avatar dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeperio-bot avatar luci-m-666 avatar marten avatar mmiller42 avatar njkevlani avatar rosshadden avatar sonnyp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

json8's Issues

How to serialize Map/Set if using a replacer?

I'm trying to use a replacer function in order to remove properties with an undefined value. However, the object to serialize also contains new Map/Set structures, which aren't properly serialized if the replacer simply returns the value:

> oo.serialize({foo: 'bar', baz: undefined, qux: new Map([['a', 1]])}, {replacer: (k,v) => v})
'{"foo":"bar","qux":{}}'

I've tried to have the replacer return oo(v) or even oo.serialize(v) but the former doesn't work, and the latter complains about undefined values.

Clarification question about diff with large object trees

Hi. I want to use diff on potentially large objects that are mainly shallow copies of each other but with some parts changed (what happens when you apply patches immutably).

To get a sense of if this library would perform well in this case, I went looking to see if there was an early return when parts were === identical.

I found https://github.com/sonnyp/JSON8/blob/master/packages/patch/lib/diff.js#L27 which seems like an early return in that case, so that's good, but given that, I was wondering if it could have returned even earlier? Like perhaps at line 11?

Feat request: Expose walk/iterator interface for JSON Pointer

Hi, currently the pointer package only exposes post-iteration dicts/index - it would be nice if the walk function an iterator/generator interface was exposed, e.g.,

for (const [ptr, val] of pointer.entries(myPointer))
  ...

Maybe entries, flatEntries, primitives, or something like that, to select what to iterate over.

Consider a pretty-print option that targets humans?

This comes from the fact that JSON8 errors when serializeing Symbols. Even if these aren’t serializable in the technical sense, there’s value in displaying, for humans, that a particular value is a Symbol.

Thanks for considering!

find Prototype pollution in add.js

Prototype pollution vulnerability in function add() in json8-patch/lib/add.js in json8-patch1.0.6 via the function add and variable add
The function usevariable partent and function add lead to Prototype pollution in line 43

Objects with arrays that change create wordy patches

I noticed that json8-patch seems to be quite fast, with the exception of arrays. Consider the following:

var obj = {
    "x": "SomeVal",
    "y": [{ "z": 2}, {"z": 3}, {"z": 4}, {"z": 5}]
}

var obj2 = {
    "x": "SomeVal",
    "y": [{ "z": 2}, {"z": 6}, {"z": 4}, {"z": 5}]
}

I would expect this to return a patch of:

[
  {
    "op": "replace",
    "path": "/y/1/z",
    "value": 6
  }
]

Instead, it returns:

[
  {
    "op": "replace",
    "path": "/y",
    "value": [
      {
        "z": 2
      },
      {
        "z": 6
      },
      {
        "z": 4
      },
      {
        "z": 5
      }
    ]
  }
]

Are they any plans for supporting objects within arrays without replacing the entire array?

serializing a map with numeric key's doesnt work

hi,

serializing a map with numeric keys does not work and ends in something like

TypeError: 21 key is not a string

import * as oo from 'json8';

const v = new Map();
v.set(4,5);

oo.serialize(v);
``

Nice library!

just tried it out an a 22mb json file, and compared a couple of libraries:

json8-patch: 90ms
jiff: 960ms (ie: > 10 slower)
fast-json-patch: failed, couldn't parse the document
impressive !

NPM packages are not available

Can't install text-sequence and merge-patch-to-patch from NPM registry:

npm install text-sequence merge-patch-to-patch 

Look like these packages are missed.

Simple replacer produces invalid JSON

Here's a simple usage of a replacer function that aims to remove properties with an undefined value:

> s = oo.serialize({foo: 'bar', baz: undefined}, {replacer: (k,v) => v})
'{"foo":"bar",}'

> JSON.parse(s)
SyntaxError: Unexpected token }
    at Object.parse (native)

If the property removed is the last in the object, then the serialization leaves an extra comma.

Prototype Pollution Vulnerability in "json8-merge-patch"

Prototype Pollution:
This package fails to restrict access to prototypes of objects, allowing for modification of prototype behavior, which may allow obtaining sensitive information/DoS/RCE.

If required I can submit a POC through a secured channel. Thanks.

patch not reversible

take this input :

[{"nom":"joe","age":26},{"age":30,"nom":"arnaud"},{"age":26,"nom":"émilie"}]

apply this patch :

[{"op":"remove","path":"/1"},{"op":"move","from":"/0/age","path":"/1/age"},{"op":"add","path":"/-","value":"essai"}]

the revert patch produced by buildRevertPatch do not revert data.
In fact, move operation overwrite an existing value and revert fail to restore it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.