Code Monkey home page Code Monkey logo

d3-create-json's Introduction

d3-create-json

Create json in your d3 program. To install: copy the code from each file to your d3 system. I'm using d3/linux. Then flash compile-catalog each subroutine/d3 program.

File Name Subroutine Description
test_d3_creating_json JSON.EXAMPLE Main d3 program that makes calls to the subroutines to generate json.
build_json_object_sub BUILD.JSON.OBJECT Only use this when you want to create an object as assign it to a key. calls CREATE.KEY.VALUE.PAIRS and assigns the object to a key that was passed to it. See Example 2
create_value_pairs_sub CREATE.KEY.VALUE.PAIRS Convert dynamic array to json object.
json_add_object_sub JSON.ADD.OBJECT Precondition: A call to JSON.START.ARRAY must begin the json array...Adds an object to the current json array...closes the array if the last argument is 1 else appends a comma
json_start_array_sub JSON.START.ARRAY Begins a json object and assigns the array to a key
  • This program was designed to build the json data structure by appending data in json format to a string as a program is being executed.
  • This program was not designed to build a large dynamic array then call a subroutine & magically poof... json then appears.
  • But maybe you can get cleaver and loop through your dynamic array, and build your json string using these subroutines.
    • you might have to pull data out of your array and create a new dynamic array that represents the <X,key>,<X,value> format for one record at a time.
  • Remember to start your json string { ...before a call to BUILD.JSON.OBJECT and also before you start a json array using JSON.START.ARRAY.
  • Remember to end your json string } ...when you want to end your json structure
  • CREATE.KEY.VALUE.PAIRS will return a json object that contains key:value pairs so if that is all you need then you don't need to start/end { } your json string. See Example 3
  • To create an json array of objects : see Example 1 in JSON.EXAMPLE d3 program
  • First begin your array by making a call to JSON.START.ARRAY and pass the key that you want the array set to and the variable name of the json string
  • Then build a dynamic array that represents all of the key value pairs for one record. (example: 1 employee or 1 resource)
    • Each Attribute represents one key/value pair. <X,1>=@:key, <X,2>=value
      • <X,1>="[DataTypeCode]:key" ...replace [DataTypeCode] with one of the characters that identify which data type you want for this field
        • @=string
        • #=number
        • !=boolean ...value should set to "1" which will converted true in json else false
        • $=object
    • call CREATE.KEY.VALUE.PAIRS and pass that dynamic array which will be converted to a json object that contains key:value pairs
    • then add that object to the current json array by calling JSON.ADD.OBJECT
      • remember to indicated if this is the last object in the array by passing 1 in the last argument, else a comma will be appended to the object.
    • REMEMBER to end the json string }
  • Create a simple json object that is assigned to a key Example 2
    • Create dynamic array <X,1>=@:key, <X,2>=value
    • Call BUILD.JSON.OBJECT
  • Create a json object with no key Example 3
    • Create dynamic array <X,1>=@:key, <X,2>=value
    • Call CREATE.VALUE.PAIRS

d3-create-json's People

Contributors

richardottinger avatar

Watchers

 avatar  avatar

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.