Build JSON from NotesView with support of multi-value fields

_fld:="refName":"refSub":"refStrength":"refWeakness";

json:="";

@For(n :=1; n<=@Elements(_fld); n:= n + 1;

@If(
	@Elements(
		@GetField(_fld[n])
		)>1;
			json := json +  @Transform ( _fld[n]; "_fn" ;  "\"" + _fn + "\":") + "[" + @Implode(@Transform( @GetField(_fld[n]) ; "_fn" ; "\"" + _fn + "\"" ) ; ",") + "]," ;
			json := json +
				@Transform (
					_fld[n]; "_fn" ; "\"" + _fn + "\":\"" + @Text ( @GetField ( _fn) ) + "\"" + ",")
	)
);


"{ \"unid\":\""
+@Text(@DocumentUniqueID)+"\"," + @LeftBack(json;1) + + "}"





Inspired by this XSnippet: https://openntf.org/XSnippets.nsf/snippet.xsp?id=use-transform-to-build-json-and-consume-the-output-in-an-xagent

Formula
Patrick Kwintensson
September 26, 2016 9:15 AM
Rating
12

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...