Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix primitive list handling #3

Merged
merged 1 commit into from Nov 6, 2020

Conversation

Shotster
Copy link
Contributor

@Shotster Shotster commented Nov 6, 2020

Previously, all arrays were assumed to be arrays of objects. As a result, arrays of strings, numbers, or booleans would be incorrectly handled. String array items would each be converted to an array of characters, and boolean or number array items would be converted to empty objects.

This fix simply uses the "primitive" array itself as the converted value.

Specifically, given the following as input...

{
    "obj1": {
        "str": "str",
        "num": 84746,
        "boo": false,
        "obj2": {
            "str_ar": [
                "str1",
                "str2",
                "str3"
            ],
            "num_ar": [
                123.0,
                8,
                87.032
            ],
            "bool_ar": [
                false,
                true,
                true
            ]
        }
    }
}

...the following would have been output...

{
    "_p_obj1.str"          : "str",
    "_p_obj1.num"          : 84746,
    "_p_obj1.boo"          : false,
    "_p_obj1.obj2.str_ar"  : [
	    {
		    "_p_0" : "s",
		    "_p_1" : "t",
		    "_p_2" : "r",
		    "_p_3" : "1"
	    },{
		    "_p_0" : "s",
		    "_p_1" : "t",
		    "_p_2" : "r",
		    "_p_3" : "2"
	    },{
		    "_p_0" : "s",
		    "_p_1" : "t",
		    "_p_2" : "r",
		    "_p_3" : "3"
	    }
    ],
    "_p_obj1.obj2.num_ar"  : [
	    {},
	    {},
	    {}
    ],
    "_p_obj1.obj2.bool_ar" : [
	    {},
	    {},
	    {}
    ]
}

With this fix, the output is now...

{
	"_p_obj1.str"          : "str",
	"_p_obj1.num"          : 84746,
	"_p_obj1.boo"          : false,
	"_p_obj1.obj2.str_ar"  : [
		"str1",
		"str2",
		"str3"
	],
	"_p_obj1.obj2.num_ar"  : [
		123,
		8,
		87.032
	],
	"_p_obj1.obj2.bool_ar" : [
		false,
		true,
		true
	]
};

@Lottemint Lottemint merged commit 31a2239 into Lottemint:master Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants