Code Monkey home page Code Monkey logo

iontojson's Introduction

Ion to JSON

Converts Amazon Ion to JSON.

npm install ion-to-json

TypeScript Sample

import { ionToJSON } from "ion-to-json";
import { makeReader, Reader } from "ion-js";

let json;

let reader: Reader = makeReader('{hello: "world"}');
json = ionToJSON(reader);

console.log(json);
console.log(json.hello);

let unformatted: Reader = makeReader('{level1: {level2: {level3: "foo"}, x: 2}, y: [1,2,3]}');
json = ionToJSON(unformatted);

console.log(json);
console.log(json.level1.level2.level3)

let sampleArray: string = `[{
    VIN: "1HVBBAANXWH544237",
    Type: "Semi",
    Year: 2009,
    Make: "Ford",
    Model: "F 150",
    Color: "Black"
    },
    {
    VIN: "3HGGK5G53FM761765",
    Type: "Motorcycle",
    Year: 2011,
    Make: "Ducati",
    Model: "Monster 1200",
    Color: "Yellow"
    }]`;

let arrayTest = makeReader(sampleArray);
json = ionToJSON(arrayTest)

console.log(json)
console.log(json[0].Color)

Javascript Sample

"use strict";

var iontojson = require("ion-to-json");
var ion = require("ion-js");

var json;

var reader = ion.makeReader('{hello: "world"}');
json = iontojson.ionToJSON(reader);
console.log(json);
console.log(json.hello);

var unformatted = ion.makeReader('{level1: {level2: {level3: "foo"}, x: 2}, y: [1,2,3]}');
json = iontojson.ionToJSON(unformatted);
console.log(json);
console.log(json.level1.level2.level3);

var sampleArray = `[{
    VIN: "1HVBBAANXWH544237",
    Type: "Semi",
    Year: 2009,
    Make: "Ford",
    Model: "F 150",
    Color: "Black"
    },
    {
    VIN: "3HGGK5G53FM761765",
    Type: "Motorcycle",
    Year: 2011,
    Make: "Ducati",
    Model: "Monster 1200",
    Color: "Yellow"
    }]`;

var arrayTest = ion.makeReader(sampleArray);
json = iontojson.ionToJSON(arrayTest);
console.log(json);
console.log(json[0].Color);

A very nice use case will be with Amazon QLDB.
Pass your result.getResultList() to the utility function
And violá! There you are with Javascript Object (JSON)

Disclaimer : Kudos to https://github.com/Lepozepo/qldb

iontojson's People

Contributors

kotojallow avatar kotosim avatar olbapmar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

iontojson's Issues

Issue with converting array of arrays...

Hi! I was trying to use your utility to convert a GeoJson ion object back to JSON. However, I ran into an issue where ionToJSON doesn't work with coordinate arrays of arrays (i.e., polygons).

Take a look at the console output in mounted.js from this example. Specifically, if you drill down into the feature collection/features/coordinates you will see the array of arrays is not converted back to JSON correctly... Thoughts?

Thanks!

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.