Comments (5)
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.
Merged #10
from json3.jl.
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.
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.
Sorry for being slow here, here's some more improvements: #16
from json3.jl.
Related Issues (20)
- Alternative to wrapper types? HOT 1
- Serializing/deserializing nulls vs. empty vectors HOT 1
- `JSON3.read` doesn't call `construct(T, args...; kw...)` for `Struct` types HOT 1
- new patch version ? HOT 1
- Bug in JSON3.@generatetypes - identified Int64 instead of Float64 HOT 1
- `JSON3.read(json; jsonlines=true)` can't handle trailing newlines
- Add partially typed objects
- StructTypes.Mutable() does not call the inner constructor
- Error Handling Fields
- Core dumped when writing DateTime HOT 1
- Errors deserialising structs without fields HOT 4
- Why `JSON3.read` is used both for file path and json string content, and blocks file after read? HOT 5
- Allow for a partial parse
- Pretty printing doesn't escape quotes HOT 1
- JSON3 version 1.14.0 not compiling on julia 1.10 HOT 1
- Progress bar?
- `@inline`-statements in src/structs.jl seem to bloat the precompiled size and slow TTFX
- DataFrameRows iterator (from DataFrames.eachrow) repeats entire dataframe when serialising with JSON3
- allow_inf and pretty don't play well together
- Pretty printing of 1D arrays in rows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json3.jl.