@@ -127,30 +127,39 @@ Method SetValueAt(
127127 pKey As %String = " " ) As %Status
128128{
129129 Set tSC = $$$OK
130- Set tJSON = {}.%FromJSON (..json )
131- Set tPath = ..ConvertPath (pPropertyPath )
132-
130+ // if pAction is set, use jsonpath to set the value
131+ // if pAction is clear, use jsonpath to remove the value
132+ // if pAction is append, use jsonpath to append the value
133+ // if pAction is insert, use jsonpath to insert the value, using pKey as the key
133134 Try {
134- If pAction = " set" {
135- Do tJSON .%Set (tPath , pValue )
135+ // Convert pPropertyPath to a a jsonpath
136+ Set tPath = ..ConvertPath (pPropertyPath )
137+
138+ Set pyjson = ##class (%SYS.Python ).Import (" json" )
139+ Set jp = ##class (%SYS.Python ).Import (" jsonpath_ng" )
140+ Set builtins = ##class (%SYS.Python ).Builtins ()
141+
142+ Set tJSON = pyjson .loads (..json )
143+
144+ Set parser = jp .parse (tPath )
145+ if pAction = " set" {
146+ Set tJSON = parser .update (tJSON , pValue )
136147 }
137- ElseIf pAction = " append" {
138- Set current = tJSON .%Get (tPath )
139- If current = " " {
140- Do tJSON .%Set (tPath , pValue )
141- }
142- Else {
143- Do tJSON .%Set (tPath , current _ pValue )
144- }
148+ ElseIf pAction = " clear" {
149+ Set tJSON = parser .remove (tJSON )
145150 }
146- ElseIf pAction = " remove " {
147- Do tJSON . %Remove ( tPath )
151+ ElseIf pAction = " append " {
152+ Set tJSON = parser . append ( tJSON , pValue )
148153 }
149- Else {
150- Set tSC = $$$ERROR($$$GeneralError, " Invalid action: " _ pAction )
154+ ElseIf pAction = " insert " {
155+ Set tJSON = parser . insert ( tJSON , pValue , pKey )
151156 }
152- }
153- Catch ex {
157+
158+ Set tResult = pyjson .dumps (tJSON )
159+ Set ..json = tResult
160+ Set ..classname = ..DocType
161+
162+ } Catch ex {
154163 Set tSC = ex .AsStatus ()
155164 }
156165 Return tSC
0 commit comments