Skip to content

Instantly share code, notes, and snippets.

@Lissy93 Lissy93/json2array.js

Last active Nov 11, 2019
What would you like to do?
A simple function to convert any flat JSON object to an array of keys and values
* Copyright Alicia Sykes <>
* Licensed under MIT X11:
* Converts a given JSON object into an array
* Where { key: 'Value' } --> ['key': 'value']
* @param json - the object to be converted
const json2array = (json) => {
const result = [];
const keys = Object.keys(json);
keys.forEach((key) => {
result.push({ key, value: json[key] });
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.