File:  [ELWIX - Embedded LightWeight unIX -] / libelwix / example / test_valid.c
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Mon Aug 25 13:00:37 2025 UTC (6 days, 23 hours ago) by misho
Branches: MAIN
CVS tags: elwix6_9, HEAD, ELWIX6_8
Version 6.8

#include <stdio.h>
#include <elwix.h>


int
main(int argc, char **argv)
{
	int pos = 0, started = 0;
	char line[BUFSIZ] = { 0 }, str[BUFSIZ] = { 0 }, str2[BUFSIZ];
	json_t json;

	if (argc > 1) {
		printf("validate=%d\n", json_validate(argv[1], &started));
		printf("started=%d\n", started);
	}

	printf("Input test JSON for marshaling> ");
	while (!feof(stdin)) {
		fgets(line, sizeof line - 1, stdin);
		strlcat(str, line, sizeof str);

		if (json_validate(str, &started))
			break;
	}
	strlcpy(str2, str, sizeof str2);

	json_init(&json, 0);
	printf("json_parse num tokens=%d\n", json_parse(&json, str, sizeof str, NULL, 0));
	json_free(&json);

	if (json_marshaling(str, 0))
		printf("Marshaled JSON with spaces> %s\n", str);
	if (json_marshaling(str2, 1))
		printf("Marshaled JSON> %s\n", str2);
	return 0;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>