JSON+C parsing for MATLAB

버전 1.1 (3.59 KB) 작성자: Sean Bone
A simple parser for JSON with Comments written in MATLAB
다운로드 수: 44
업데이트 날짜: 2022/3/2

JSON+C parsing for MATLAB

View matlab-json-c on File Exchange

This package offers some simple functions to handle JSON+C (JSON with comments) in a MATLAB script.

  • jsonc.removeJSONComments removes JavaScript-style comments from the string (or char array) you give it as argument.
  • jsonc.jsoncDecode is a wrapper for MATLAB's native jsondecode. It filters the string you give it though jsonc.removeJSONComments before passing it to jsondecode.
  • jsonc.jsonEncode is a wrapper for MATLAB's native jsonencode. This tries to use the PrettyPrint option if it is supported (which depends on your MATLAB version).

The demo.m script shows example usage.

>> demo
Original string:
{
	// One-line comment
	"foo": "bar", // One-line comment at end of line
	/*
		Multiline comment
	*/
	"singleLinerInString": "//",
	"multilinerInString": "/*",
	"*/": "baz"
}

String without comments:
{

	"foo": "bar", 

	"singleLinerInString": "//",
	"multilinerInString": "/*",
	"*/": "baz"
}


recoveredData = 

  struct with fields:

                    foo: 'bar'
    singleLinerInString: '//'
     multilinerInString: '/*'
                    x__: 'baz'

Data re-encoded to JSON:
{
  "foo": "bar",
  "singleLinerInString": "//",
  "multilinerInString": "/*",
  "x__": "baz"
}

But why?

The JSON standard does not allow for comments. However, it is often convenient to allow for them when using JSON as a markup language for configuration files and the likes. Hence the need for the not-quite-official JSON+C variant.

Although there is already a similar implementation on the MATLAB file exchange, that relies on an external JSON parser and requires you to compile it with MEX for your target platform(s). This is a much more lightweight alternative implemented in "vanilla" MATLAB.

인용 양식

Sean Bone (2024). JSON+C parsing for MATLAB (https://github.com/seanbone/matlab-json-c/releases/tag/v1.1), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2021a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
태그 태그 추가

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.1

See release notes for this release on GitHub: https://github.com/SeanBone/matlab-json-c/releases/tag/v1.1

1.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.