Giter Club home page Giter Club logo

Comments (2)

NateEag avatar NateEag commented on August 17, 2024

Additional note: while NodeJS's JSON.parse() yields identical results for the two above documents, some tools do not, such as PHP 8.1's json_decode:

<?php

$old = json_decode('{"amount": 42.0}');
$new = json_decode('{"amount": 42}');

if ($old->amount === $new->amount) {
    echo "equal\n";
} else {
    echo "not equal\n";
}
// outputs 'not equal'

That's because unlike JS, PHP has distinct float and integer types and it parses the two fields as two different types due to the decimal point's presence/absence.

That may be the Wrong Thing (as is true of so much of PHP), but it's a relevant point, since it is a widely-deployed web programming language that does not treat the sample documents as semantically identical.

from json-diff.

sora-blue avatar sora-blue commented on August 17, 2024

Here are similar cases with numbers that is too large, e.g. 282231934395265024. After running json-diff, it will be round down to 282231934395265020 in the output. I suppose it is because precision of floating number in JavaScript is limited?

from json-diff.

Related Issues (20)

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.