47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
|
/*
|
||
|
* Copyright (c) 2009, 2010 Petri Lehtinen <petri@digip.org>
|
||
|
*
|
||
|
* Jansson is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the MIT license. See LICENSE for details.
|
||
|
*/
|
||
|
|
||
|
#include <jansson.h>
|
||
|
#include <string.h>
|
||
|
#include "util.h"
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
json_t *json;
|
||
|
char *result;
|
||
|
|
||
|
/* Encode an empty object/array, add an item, encode again */
|
||
|
|
||
|
json = json_object();
|
||
|
result = json_dumps(json, 0);
|
||
|
if(!result || strcmp(result, "{}"))
|
||
|
fail("json_dumps failed");
|
||
|
|
||
|
json_object_set_new(json, "foo", json_integer(5));
|
||
|
result = json_dumps(json, 0);
|
||
|
if(!result || strcmp(result, "{\"foo\": 5}"))
|
||
|
fail("json_dumps failed");
|
||
|
|
||
|
json_decref(json);
|
||
|
|
||
|
json = json_array();
|
||
|
result = json_dumps(json, 0);
|
||
|
if(!result || strcmp(result, "[]"))
|
||
|
fail("json_dumps failed");
|
||
|
free(result);
|
||
|
|
||
|
json_array_append_new(json, json_integer(5));
|
||
|
result = json_dumps(json, 0);
|
||
|
if(!result || strcmp(result, "[5]"))
|
||
|
fail("json_dumps failed");
|
||
|
free(result);
|
||
|
|
||
|
json_decref(json);
|
||
|
|
||
|
return 0;
|
||
|
}
|