Skip to content

Reduce Verbiage in Serialize Command #35

@rydtran

Description

@rydtran

The current serialize command can become verbose when converting a large serialized JSON string with nested subtrees into a JSON file. I propose adding an additional syntax to reduce the verbiage. Or even introduce a new command called deserialize that will convert a serialized tree into a JSON file.

Proposal:
  A new syntax added to serialize.
    or
  A new command called deserialize. I'm more inclined to this option since the name accurately describes the proposed behavior.

We will use the following JSON to demonstrate the differences;

{
  "people" : {
    "ryan" : {
      "age" : 23,
      "hobbies" : {
        "soccer" : "good",
        "running" : "bad"
      },
      "status" : "insomina"
    },
    "john" : {
      "age" : 45,
      "hobbies" : {
        "soccer" : "bad",
        "running" : "good"
      },
      "status": "sad"
    }
  }
}

Old Syntax:

spellbook serialize --output myfile.json --vars \
people/ryan/age=23 \
people/ryan/hobbies/soccer=good \
people/ryan/hobbies/running=bad \
people/ryan/status=insomania \
people/john/age=45 \
people/john/hobbies/soccer=bad \
people/john/hobbies/running=good \
people/john/status=sad\

New Syntax:

spellbook deserialize --output myfile.json \
people>\
ryan>age=23&hobbies>soccer=good&running=bad<status=insomania<\
john>age=45&hobbies>soccer=bad&running=good&status=sad\

Breaking Down the Syntax:

  • ">" tells the program that the next value to read is a child node.
  • "<" tells the program to return to the parent node.
  • "&" tells the program that the next value to read is a sibling node.

Things to Note:

  • After specifying "hobbies" and its child nodes, a "<" symbol is appended. The first instinct is to append "&," but a "<" symbol is needed to tell the program to return to the parent node of "hobbies." This will correctly place "status" as a sibling of "age" and "hobbies."
  • The optional variable "--vars" is not needed since the serialized tree is one continuous string with no spaces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions