ansteh / shape-json

Module used to convert a flat json array into a nested json object with a predefined scheme
MIT License
31 stars 7 forks source link

shape-json ignore string "" #9

Closed he-yang closed 7 years ago

he-yang commented 7 years ago

In JSON, sometimes we would have something like this.

{"Name": "David", "Age":20, "Comment":""}

In the above JSON , the comment field is a string type and there is nothing in it.

Shape-json ignores "" by default, is there a way to have "" included.

ansteh commented 7 years ago

Hi Yang, confirmed, i will fix it

ansteh commented 7 years ago

This test works now: test code in repo

    let input = [
      {"Name": "Tom", "Age":20, "Comment":""},
      {"Name": "Jerry", "Age":18, "Comment":"Catch me if you can!"},
    ]

    let scheme = {
      "$mirror[people](Name)": {
        "name": "Name",
        "age": "Age",
        "comment": "Comment"
      }
    };

    let result = {
      people: [
        {name: "Tom", age: 20, comment: ''},
        {name: "Jerry", age: 18, comment: 'Catch me if you can!'},
      ]
    };

    // console.log(JSON.stringify(shape.parse(input, scheme), null, 2));

    expect(shape.parse(input, scheme)).toEqual(result);// true
he-yang commented 7 years ago

Thank you Andre for the prompt response.

------------------ Original ------------------ From: "Andre Stehle"; Date: 2017年7月13日(星期四) 凌晨2:39 To: "ansteh/shape-json"; Cc: "He Yang"; "Author"; Subject: Re: [ansteh/shape-json] shape-json ignore string "" (#9)

Closed #9.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.