Skip to content

DMBerlin/json-parsefy

Repository files navigation

JSON-PARSEFY

This project helps with flattening JSON strings who have repeatedly through a stringed process. It applies a JSONParse method on a stringify data and repeat the process through each node, flattening it until it becomes a JSON object.

Example:

const before: string = "{\"name\": \"John Doe\",\"age\": \"30\",\"location\": {\"city\": \"Some City\",\"state\": \"Some State\",\"geo\": \"{\\\"lat\\\": \\\"40000\\\",\\\"lng\\\": \\\"40000\\\"}\"},\"rules\": {\"localWork\": \"true\",\"onlineWork\": \"true\",\"applications\": {\"admin\": \"true\",\"time\": \"no-time\"}},\"availability\": \"{\\\"online\\\": \\\"true\\\"}\"}";

Use Parsefy to do a BFS JSON parse on the string.

import { Parsefy } from "json-parsefy";
const after = Parsefy.this(before);

How it should look after parsing:

const after: Record<string, any> = {
  name: "John Doe",
    age: 30,
  location: {
  city: "Some City",
    state: "Some State",
    geo: { lat: 40000, lng: 40000 },
},
  rules: {
    localWork: true,
      onlineWork: true,
      applications: { admin: true, time: "no-time" },
  },
  availability: { online: true },
};

About

Correct any json string that has been through a loop of stringfy methods to remove unecessary escaped strings.

Resources

Stars

Watchers

Forks

Packages

No packages published