GithubHelp home page GithubHelp logo

d3-create-json's People

Contributors

richardottinger avatar

Stargazers

 avatar

Forkers

rnottinger

d3-create-json's Issues

Bug when adding a single item to an array

This is a great little json library. However, I found a bug.

In JSON.ARRAY.ADD.OBJECT, on line 3, you have: IF CURRENT < TOTAL

However...this doesn't take into account the case where you only have one item in the array. When you have only one item, then Current = Total, and you won't prepend the "[" to the array (which happens on line 4), because you don't get past the if condition on line 3 (since CURRENT = TOTAL when there is only 1 item in the array).

Instead, you want to have CURRENT <= TOTAL on line 3, and then enforce the CURRENT < TOTAL inside that if condition.

Here is how I refactored this and I think it works:

`SUBROUTINE JSON.ARRAY.ADD.OBJECT(CURRENT,TOTAL,JSON_OBJECT,JSON_ARRAY)

  • DESCRIPTION: determines whether to PREPEND [, or APPEND a ], or append a comma to the JSON.OBJECT, then adds the current json object to the json array that is currently being built
    IF CURRENT <= TOTAL THEN
    IF CURRENT EQ 1 THEN CALL STRING.PREPEND('[',JSON_OBJECT) ;* same as JSON.OBJECT = '[' : JSON.OBJECT

    IF CURRENT < TOTAL THEN
    CALL STRING.APPEND(',',JSON_OBJECT)
    END ELSE ;* same as JSON.OBJECT := ','
    CALL STRING.APPEND(']',JSON_OBJECT)
    END
    END
    CALL STRING.APPEND(JSON_OBJECT,JSON_ARRAY) ;* same as thing as JSON.ARRAY := JSON.OBJECT
    RETURN`

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.