Code Monkey home page Code Monkey logo

extendingjson's Introduction

Extending JSON

Human-writeable JSON-like data formats for GameMaker LTS 2022.

You may also be interested in SNAP, a standard data format and struct/array utility toolkit.

 

Thanks to @gnysek for the support!

This library focuses on a couple JSON-like formats that are designed to be maximally human-writeable. JSON is a great format, I love it, but it is a format that is more easily written and read by a computer than a human. This makes JSON unhelpful for situations where a human is likely to want to modify the data.

 

Loose JSON

Loose JSON is as it sounds - a looser form of JSON. It stands somewhere between JSON and YAML and attempts to combine the familiarity of the former with the writing convenience of the latter.

Loose JSON focuses on being easy to write. It dispenses with commas and double quotes where they are not needed. Loose JSON can also contain single-line and multi-line comments. Any standard JSON is automatically parseable as Loose JSON, but Loose JSON isn't typically parseable as standard JSON.

Consider the following JSON:

{
	"graphics": {
		"width": 1920,
		"height": 1080,
		"fullscreen": true
	},
	"names": ["john and yoko", "paul", "george", "ringo"]
}

This could be written as the following loose JSON:

{
	graphics: {
		width: 1920
		height: 1080
		fullscreen: true
	}
	names: [john and yoko, paul, george, ringo]
}

In Loose JSON, the keywords true and false (without quotes) are transformed into booleans as one would expect. The keyword null (again, without quotes) is converted into GameMaker's native undefined datatype.

A string must be delimited using double quotes in the following situations:

  1. If a string needs to contain any reserved symbols (: , \n \r { } [ ])
  2. If a string needs to be exactly "true" "false" or "null"
  3. If a string must contain whitespace at the start or end

Strings can further contain escaped characters.

 

Config JSON

Config JSON is an extension to the previously described Loose JSON but is even less strict. It allows for data to be defined and overwritten, something that is usually forbidden in standard JSON (including "loose JSON" above). In the case of integers and strings, values are overwritten. Structs and arrays, however, are merged together where possible.

{
  // display info
  height: 720,
  width: 960,
  width: 1280,
  /* names */
  names: [john and yoko],
  names: ["paul", george, "ringo"],
}

This would result in GML struct:

{}
 |- height: 720
 |- names:[]
 |         |- "john and yoko"
 |         |- "paul"
 |         |- "george"
 |         \- "ringo"
 \- width: 1280

extendingjson's People

Contributors

jujuadams avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.