javascript library to convert a list of objects to a nested json output format, depending on the names in the list

Overview

formToNestedJson

javascript "library" to convert a list of objects to a nested json output format, depending on the names in the list

Basic usage

Given a form in html you can serialize it to flat json rather easily using jquery

var json = jQuery("myForm").serializeArray()

This will produce an object of the form

json = [ 
	{"name":"player.firstName", "value":"Saulius"},
	{"name":"player.lastName", "value":"TheBlack"},
];

In the provided example, the form has 2 text inputs with the names player.firstName and player.lastName

if you want to create json that is less flat, and somewhat more verbose you can manually go around and do it everytime yourself. you can also use this library, that will create the following json for you:

json = parseJsonFromForm(jQuery(formId).serializeArray());
json = { 
	"player" : {
		"firstName":"Saulius",
		"lastName":"TheBlack",
	}
};

if there are numbers included in the naming, the parser will convert it to a list:

json = [ 
	{"name":"players.0.firstName", "value":"Saulius"},
	{"name":"players.0.lastName", "value":"TheBlack"},
	{"name":"players.1.firstName", "value":"Gandalf"},
	{"name":"players.1.lastName", "value":"TheWhite"},
];
json = parseJsonFromForm(jQuery(formId).serializeArray());
json = { 
	"players" : [
		{
			"firstName":"Saulius",
			"lastName":"TheBlack",
		},
		{
			"firstName":"Gandalf",
			"lastName":"TheWhite",
		}
	
	]
};
You might also like...

This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you can build some javascript library which consumes the output of this library.

@albanian-xrm/dataverse-odata This package will help parse OData strings (only the Microsoft Dataverse subset). It can be used as a validator, or you

Oct 22, 2022

JCS (JSON Canonicalization Scheme), JSON digests, and JSON Merkle hashes

JSON Hash This package contains the following JSON utilties for Deno: digest.ts provides cryptographic hash digests of JSON trees. It guarantee that d

Sep 2, 2022

Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de créer un tunnel https pour c

Mar 29, 2022

jsonrawtoxlsx is library to convert json raw (array) into xlsx file

jsonrawtoxlsx is library to convert json raw (array) into xlsx file

Welcome to jsonrawtoxlsx 👋 ✨ What is jsonrawtoxlsx? jsonrawtoxlsx is library to convert json raw (array) into xlsx file ⚡️ Installation using npm npm

Dec 23, 2022

LiveJSON provides LiveView-like updating for JSON objects rather than DOM elements.

live_json LiveJSON provides LiveView-like updating for JSON objects rather than DOM elements. It works within your existing LiveViews - just use push_

Dec 29, 2022

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

Apr 6, 2022

Portable Activity Timeline that draws the Timeline based on data given in JSON or CSV format

Portable Activity Timeline that draws the Timeline based on data given in JSON or CSV format

Portable Activity Timeline that draws the Timeline based on data given in JSON or CSV format. By clicking on any activity a detailed modal window is displayed. Initially developed for post incident investigations to get a overview of the situation in an it-environment.

Oct 11, 2022

Fast API for getting moroccan cities and their districts in json format.

Fast API for getting moroccan cities and their districts in json format.

Fast API for getting moroccan cities and their districts in json format built with Usage The number of requests per user is limited to 100 req/min Lis

Dec 22, 2022

A JavaScript library for EASILY fetching info from TheMovieDB API with support for torrent file names.

TheMovieDB-API-Wrapper.js A easy to use, pure vanilla JavaScript API wrapper for TheMovieDB Show your support! A JavaScript library for easily fetchin

Dec 2, 2022
Releases(1.0.0)
Owner
null
A lightweight (~850 B) library for easy mac/window shortcut notation. kbd-txt convert shortcut text depending on the type of OS (window/linux/mac).

kbd-txt A lightweight (~850 B) library for easy mac/window shortcut notation. kbd-txt convert shortcut text depending on the type of OS (window/linux/

Minung Han 6 Jan 1, 2023
🔨 A more engineered, highly customizable, standard output format commitizen adapter.

cz-git Github | Installation | Website | 简体中文文档 Introduction A more engineered, highly customizable, standard output format commitizen adapter. What i

zhengqbbb 402 Dec 31, 2022
Json-parser - A parser for json-objects without dependencies

Json Parser This is a experimental tool that I create for educational purposes, it's based in the jq works With this tool you can parse json-like stri

Gabriel Guerra 1 Jan 3, 2022
Convert Tailwind CSS class names into their CSS3-equivalent styles — right from Alfred.

alfred-tailwind2css Tailwind2CSS offers you the ability to convert TailwindCSS classes into their CSS3-equivalent styles -- right from within Alfred.

Stephan Casas 6 Dec 7, 2022
Format an array of data objects as a textual table.

st2 st2 is string-table refactored in TypeScirpt with more enhancements: add type information, then it can be used in modern IDE like vscode to work w

null 6 Sep 10, 2022
A simple calculator for how many units of insulin to take with a meal depending on current and target blood sugar levels.

Insulin-Calculator One of my first programs, made to try building javascript-read HTML forms. A simple calculator for how many units of insulin to tak

Athena 1 Dec 26, 2021
An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

An npm package for demonstration purposes using TypeScript to build for both the ECMAScript Module format (i.e. ESM or ES Module) and CommonJS Module format. It can be used in Node.js and browser applications.

Snyk Labs 57 Dec 28, 2022
A command-line tool to convert Project Zomboid map data into Deep Zoom format

pzmap2dzi pzmap2dzi is a command-line tool running on Windows to convert Project Zomboid map data into Deep Zoom format. Features Supports both python

Min Xiang 14 Dec 31, 2022
Convert your Postman documentation in a github´s readme.md ready format

Postman 2 Markdown Converter For that only time you need to convert your Postman documentation in a github´s readme ready format! Features & Problems

Andres Bastias 0 Sep 18, 2022
A tool to convert scw files from Supercell games to Collada (dae) format

SCW Tools This module is intended to convert .scw files from Supercell games to Collada (.dae) format. For a better understanding of SCW file structur

Jean-Baptiste Martin 3 Oct 11, 2022