Tips for writing valid JSON
Methodical approach to finding and avoiding errors in JSON
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
⚙️ Check out my series on Automating Cybersecurity Metrics | Code.
🔒 Related Stories: Bugs | AWS Security | Secure Code
💻 Free Content on Jobs in Cybersecurity | ✉️ Sign up for the Email List
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
JSON can be very tricky to write but here are a few tips:
- Test your JSON adding small bits at a time until you find the error.
- Write your json like this, step by step, to avoid errors:
Step 1: Add starting and ending curly braces:
{}
Step 2: Add the first element with starting and ending brackets:
{ "Findings":
[ ]
}
Step 3: Add the next set of brackets:
{ "Findings":
[
{
}
]
}
Step 4: Add your elements — be careful with quotes and commas!
{ "Findings":
[
{
"Name1": "Value1",
"Name2": "Value2"
}
]
}
Writing your code in this methodical manner will help prevent errors.