Coder Social home page Coder Social logo

Comments (5)

quinnj avatar quinnj commented on August 17, 2024

Thanks for opening an issue! I included a few tweaks to help in #10. I fixed the promotion from Union{Int, Float64} to Any, and also changed so if you've parsed a Float64, then it will only try to parse Float64 for the rest of the array. The one case where you'll still get Union{Int, Float64} is a case like JSON3.read("[1.0, 2.1]"), which may not be ideal, but I'm not sure quite how we could handle that without just parsing Float64 for every number.

from json3.jl.

quinnj avatar quinnj commented on August 17, 2024

Merged #10

from json3.jl.

lbilli avatar lbilli commented on August 17, 2024

Thanks for the quick fix!

However, I still find some odd behavior:

JSON3.read("[1.2, null, 3.3]")
3-element JSON3.Array{Union{Nothing, Float64}, ... # ok

JSON3.read("[1.2, null, 3.0]")
3-element JSON3.Array{Any, ...                     # I was hoping for the same as above 

My use case is a numeric array that may contain missing values, encoded as null. It'd be useful to know whether there are any null without scanning the array, since the parser already has this information.

It already works as expected for Int64 or String.

from json3.jl.

lbilli avatar lbilli commented on August 17, 2024

Thanks again for taking care of this so promptly.

I'm sorry to keep dragging this on, but I'd like to mention that the last remaining case that is still less then ideal is when the first non-null element in a Float array happens be an Int, in which case the eltype depends on the order of the elements:

JSON3.read("[1.2, 3, null]")    # Union{Nothing, Float64}

JSON3.read("[3, 1.2, null]")    # Union{Nothing, Float64, Int64}

JSON3.read("[3, null, 1.2]")    # Any

JSON3.read("[null, 3, 1.2]")    # Any

JSON3.read("[null, 1.2, 3]")    # Union{Nothing, Float64}

from json3.jl.

quinnj avatar quinnj commented on August 17, 2024

Sorry for being slow here, here's some more improvements: #16

from json3.jl.

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.