Skip to main content
deleted 15 characters in body
Source Link
Kamil Kiełczewski
  • 93.7k
  • 34
  • 401
  • 375

Shortest

The shortest way I know toTo generate valid json from array of integers isuse

let json = `[${cars}]`

for more general object/arrayarrays use JSON.stringify(cars) (for object with circular references use this)

let cars = [1,2,3]; cars.push(4,5,6);

let json = `[${cars}]`;

console.log(json);
console.log(JSON.parse(json)); // json validation

The shortest way I know to generate valid json from array of integers is

let json = `[${cars}]`

for more general object/array use JSON.stringify(cars) (for object with circular references use this)

let cars = [1,2,3]; cars.push(4,5,6);

let json = `[${cars}]`;

console.log(json);
console.log(JSON.parse(json)); // json validation

Shortest

To generate valid json from array of integers use

let json = `[${cars}]`

for more general arrays use JSON.stringify(cars) (for object with circular references use this)

let cars = [1,2,3]; cars.push(4,5,6);

let json = `[${cars}]`;

console.log(json);
console.log(JSON.parse(json)); // json validation

added 59 characters in body
Source Link
Kamil Kiełczewski
  • 93.7k
  • 34
  • 401
  • 375

The shortest way I know to generate valid json from array of integers is

let json = `[${cars}]`

for more general object/array (without circular references) use JSON.stringify(cars) (for object with circular references use this)

let cars = [1,2,3]; cars.push(4,5,6);

let json = `[${cars}]`;

console.log(json);
console.log(JSON.parse(json)); // json validation

The shortest way I know to generate valid json from array of integers is

let json = `[${cars}]`

for more general object/array (without circular references) use JSON.stringify(cars)

let cars = [1,2,3]; cars.push(4,5,6);

let json = `[${cars}]`;

console.log(json);
console.log(JSON.parse(json)); // json validation

The shortest way I know to generate valid json from array of integers is

let json = `[${cars}]`

for more general object/array use JSON.stringify(cars) (for object with circular references use this)

let cars = [1,2,3]; cars.push(4,5,6);

let json = `[${cars}]`;

console.log(json);
console.log(JSON.parse(json)); // json validation

Source Link
Kamil Kiełczewski
  • 93.7k
  • 34
  • 401
  • 375

The shortest way I know to generate valid json from array of integers is

let json = `[${cars}]`

for more general object/array (without circular references) use JSON.stringify(cars)

let cars = [1,2,3]; cars.push(4,5,6);

let json = `[${cars}]`;

console.log(json);
console.log(JSON.parse(json)); // json validation