richardottinger / d3-create-json Goto Github PK
View Code? Open in Web Editor NEWCreate json in a Rocket d3 program
License: MIT License
Create json in a Rocket d3 program
License: MIT License
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`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.