Skip to content

Instantly share code, notes, and snippets.

View geraintluff's full-sized avatar

Geraint geraintluff

View GitHub Profile
function prettyJson(data) {
var json = JSON.stringify(data, null, "\t");
function compactJson(json) {
try {
var compact = JSON.stringify(JSON.parse(json));
var parts = compact.split('"');
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
part = part.replace(/:/g, ': ');
part = part.replace(/,/g, ', ');
// Generic renderer for arrays
// Requires "render.table" and "render.generator" plugins
Jsonary.render.register(Jsonary.plugins.Generator({
// Part of the generator plugin - this function returns a renderer based on the data/schema requirements
rendererForData: function (data) {
var FancyTableRenderer = Jsonary.plugins.FancyTableRenderer;
var renderer = new FancyTableRenderer({
rowsPerPage: 15,
cellActionHtml: {
'remove': function (data, context, actionName) {
@geraintluff
geraintluff / GolfCourse.json
Created July 8, 2013 19:37
Example schemas generated from schema.org
{
"id": "http://json-schema.org/schemas/GolfCourse.json",
"title": "Golf Course",
"description": "A golf course.",
"allOf": [{"$ref": "SportsActivityLocation.json"}],
"type": "object",
"format": "http://schema.org/GolfCourse",
"properties": {},
"definitions": {}
}
@geraintluff
geraintluff / generate.py
Last active August 29, 2017 22:39
Generate JSON Schemas from schema.org types
import urllib.request as request
import re
import os
import copy
import json
outputprefix = "schemas/"
outputsuffix = '.json'
urlprefix = "http://json-schema.org/schemas/"
urlsuffix = '.json'
@geraintluff
geraintluff / data.json
Last active March 25, 2023 07:14
Additional Relative JSON Pointer examples
{
"test": ["foo", "bar"],
"child": {
"grandchild": 12345
},
"sibling": "sibling value",
"awkwardly/named~variable": true
}
{
"items": {
"allOf": [
{...}
]
},
"definitions": {
"myFragment": {"$ref": "#/items/allOf/0"}
}
}
{
"main": "food",
"sub": "bread"
}
{
"responseStatus": {
"status": "success",
"message": "This is a valid message"
},
"data": {
"total": 2,
"collection": [
{
"id": 1,
@geraintluff
geraintluff / example1.schema.json
Created January 29, 2013 14:29
When using canonical addressing, these two schemas should behave *exactly* the same. Canonical addressing means that the use of "id" has *no* effect on schema lookup/dereferencing- so *neither* of these examples would have any effect on references to "http://example.com/other-schema#" anywhere else.
{
"title": "Some schema",
"items": {
"id": "http://example.com/other-schema",
"type": "array",
"items": {"$ref": "#"}
}
}
{
"properties": {
"someProperty": {
"id": "http://other.site/schema",
"type": "array",
"items": {"$ref": "itemSchema"}
}
}
}