Giter Site home page Giter Site logo

Unable to encode 'sparse array's about json.lua HOT 5 CLOSED

rxi avatar rxi commented on July 30, 2024
Unable to encode 'sparse array's

from json.lua.

Comments (5)

rxi avatar rxi commented on July 30, 2024

This becomes a problem in scenarios where you have a table as such:

{ [1] = true, [1000000] = true }

If you want to encode a sparse array you should either manually replace the missing values with false, convert the keys to string before encoding, or use a format other than JSON.

from json.lua.

makarov-roman avatar makarov-roman commented on July 30, 2024

Hi @rxi,
Can you please clarify why such structure cannot be converted into JSON {"1": true, "1000000": true}?

from json.lua.

rxi avatar rxi commented on July 30, 2024

@makarov-roman See #12

from json.lua.

makarov-roman avatar makarov-roman commented on July 30, 2024

I see your point, but sometimes you don't care if [1] became "1" (exactly my case). I've managed to export data with https://github.com/harningt/luajson which treat numbers this way.
It would be nice to have on option for this under flag. convertNumberKeysToStrings or something.

from json.lua.

TomMD avatar TomMD commented on July 30, 2024

I like that this failed. I had an "array" indexed at zero. Very happy that I saw a failure rather than JSON going out in the form { "0" : val1, "1" : val2 }.

from json.lua.

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.