JSON

Syndicate content 17 

We have a business service that extends Ens.BusinessService and uses  EnsLib.File.InboundAdapter.

This service polls for json files in a folder.

Method signature is like this:

Method OnProcessInput(pInput As %FileCharacterStream, pOutput As %RegisteredObject) As %Status

And inside that method it tries to read the content like this:

Last answer 5 days ago Last comment 4 days ago
0   0 3
103

views

0

rating

Hi all,

I have a class that I want to serialize to JSon. So I'm using the object %ZEN.Auxiliary.jsonProvider)

set myClass = ##class(myapp.myclass).%New()

set myClass.property1 ="value 1"

set myClass.property2 = "value 2"

set myClass.property3 = "value 3"

do ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(.tStream,myClass ,,,1,"ed")

write tStream.Read()

By definition of myclass, all properties are serialized, that's fine. But I want not serialize the property3. I think is using a XML attribute in the property, or something about. But I didn't find anything about.

 

Anyone can help me?

 

Last answer 7 days ago Last comment 7 days ago
0   0 2
80

views

0

rating

I am still new to cache objectscript and am trying to figure out how I would go about removing the escape characters from my JSON below. When I call the $toJSON method it's adding the "\" character in the file path.

 

{"FileStatus":"P","Path":"\/somepath\/test\/test123\/filename.txt","InterchangeOID":"100458"}

My Code

Last answer 23 April 2019 Last comment 2 May 2019
0   0 5
196

views

0

rating

Referencing this post:

https://community.intersystems.com/post/producing-json-sql

I'm not sure how to actually interact with the result set I get from doing something like this.  I want to return something like:

[{"field1":1, "field2":2}, {"field1":2, "field2":10}]

I'm finding it very difficult to get it in this format, since %Print appends a newline onto the end of the {} object it prints.

Here's the closest I've gotten:

set query = "select JSON_OBJECT('field1': field1, 'field2":field2) from MyTable where x=? and y=?"

    set tStatement = ##class(%SQL.Statement).%New()
    set qStatus = tStatement.%Prepare(query)
    if qStatus'=1 {WRITE "%Prepare failed:" DO $System.Status.DisplayError(qStatus) QUIT

Last answer 13 April 2019 Last comment 16 April 2019
0   2 1
169

views

0

rating

Hi Dev Community,

My team is currently working on a project where we need to post pdf documents to a 3rd party REST API.

The API specifies a field in the JSON request message to contain the 'physical content' of the file as an array of bytes, example of the JSON request as follows - data truncated for readability purposes:

{
    "CaptureSource":2,
    "RecipientID":"ID34",
    "Document": {
        "Guid":"5D847A4E9CC1485382DC4A5F5DC80D6C",
        "EventDate":"2019-01-14T13:23:46",
        "FileExtension":"pdf",
        "FileContent":"JVBERi0xLjQNCiXi48/TDQoxIDAgb2JqDQogIDw8DQogICA......"

      },
    "ActionRequired":false,

Last answer 12 April 2019
0   1 2
0

comments

146

views

0

rating

Dear Colleagues and Friends,

is there any indication that the .NET object representation of Cache objects (i.e. InterSystems.Data.CacheClient.dll) complies with .NET Standard? I'm planning to extend our existing .NET client/server solution with a mobile option by Xamarin Forms and can't find any significant hints in the internet.

I'm just fooling around a bit and made some expreiments with a REST API and a generic object-to-JSON tier

Last comment 1 April 2019
0   0 2
0

answers

66

views

0

rating

Hello folks,

I have an JSON object that need to be updated before being parsed into a JSX component.

Source JSON obj:

var Obj = { "data": [
  {"id":1, "text":"Task #1", "project":"10", "sub_project":"10-1" },
  {"id":2, "text":"Task #2", "project":"10", "sub_project":"10-1" },
  {"id":3, "text":"Task #3", "project":"11", "sub_project":"11-1" },
]};

 

Required JSON obj result:

var Obj = { "data": [

  {"id":10, "text":"Project 10" },
  {"id":11, "text":"Project 11" },

  {"id":10-1, "text":"Sub Project 10-1", "project":"10" },
  {"id":11-1, "text":"Sub Project 11-1", "project":"11" },

  {"id":1, "text":"Task #1", "project":"10", "sub_project":"10-1" },
  {"id":2, "text":"Task #2", "project":"10", "sub_project":"10-1" },
  {"id":3, "text":"Task #3", "project":"11", "sub_project":"11-1" },

Last answer 7 March 2019
0   0 2
0

comments

79

views

0

rating

Hello,

I'm trying to convert JSON response to object in cache 2010.

My Code is bellow:

set sc = ##class(%ZEN.Auxiliary.jsonProvider).%ParseJSON(resptext,,.pObject,1)

my JSON response

{"access_token":"DSAFFDSGFDGTRHTRHTRH","in":"2522","refresh":"","scope":"send","token_type":"Bearer"}

the result : "9@%ZEN.proxyObject" 

Last answer 22 February 2019 Last comment 22 February 2019
0   0 1
90

views

0

rating

Hi All,

I am trying to get JSON data from a REST api.  I am using my web browser to get the data by hitting the URL.

The data is receiving properly, but the JSON contains a few HTML tags.

These tags are not not receiving in the browser while hitting the url. Is there any way to overcome this issue ?

Thanks,

Last answer 16 February 2019 Last comment 13 February 2019
0   1 3
98

views

0

rating

Hello.

I just noticed that whenever I parse a JSON using %FromJSON, it always return the property values as primary data types, including long strings.

I did a quick stress test to measure it's capabilities and found out that characteristic,  this is something I needed to figure out beforehand  to implement my REST lib.

What I concluded is that %Dynamic depends solely on volatile storage? What if the user doesn't have long string support enabled or if the server has not enough memory to handle long strings?

Is there a fallback for handling it?

Please note that is an extreme and unusual use case, specially the last one, but I wanted to figure how to handle it accordingly.

Last answer 9 August 2017 Last comment 13 February 2019
0   2 5
453

views

0

rating

I created the Process to extract the required data from ADT message to a Dynamic Object. I wanted to send the JSON stream to EnsLib.File.PassthroughOperation operation and generate a file with the content of JSON stream.

Here are the codes for Process:

set oMetadata = ... /// metadata is from ADT message which is dynamic object

set jsonRequest = ##class(%ZEN.Auxiliary.jsonProvider).%ObjectToJSON(oMetadata)
set tSC = ..SendRequestAsync(..JSONOperation,jsonRequest,0,,..MetadataContext)  /// send the jsonRequest to operation

Here are the errors in the operation: "ERROR <Ens>ErrGeneral: No MessageBody classname for MessageHeader

Last answer 12 December 2018 Last comment 9 January 2019
+ 1   0 3
205

views

+ 1

rating

Hi all,

I have an incoming JSON message with a string field exceeding in length the 'caché long-string limit' of 3641144 characters.

Using {}.%FromJSON(instream) I am able to create %DynamicObject properly. However, I am unable to access the long property, as in every assignment, I get the <MAXSTRING> error.

Is there any way for me to obtain contents of the 'too long' string field as a stream?

Thanks

Jiri

Last answer 28 November 2018 Last comment 9 November 2018
0   0 3
281

views

0

rating

When using the JSON_OBJECT() function in Caché SQL on a %String property that contains JSON syntax, it converts the %String into a JSON object instead of escaping it as a string literal. How can I prevent this? (without ridiculous hacks like "add a space to the beginning of the value" as we don't always know which properties will contain these values and I certainly don't want to have to check for nulls and add/remove a space every single place this value is used in the application)

I don't want these strings automatically marshalled into JSON objects.

For example:

SELECT ID, JSON_OBJECT('ID': ID, 'Name':, LastName || ', ' || FirstName, 'Options': Options) as Item FROM Whatever.Whatever

Should give me:

1, '{"ID":1,"Name":"Smith, John","Options":"{\"Color\":\"Blue\",\"Count\":20}"}'

And instead is giving me the marshalled version:

1, '{"ID":1,"Name":"Smith, John","Options":{"Color":"Blue","Count":20}}

Last answer 20 November 2018 Last comment 28 November 2018
0   0 3
167

views

0

rating

I am trying to use the automated unittest class for a %CSP.Rest service.

So my Unittest code set's %request and %response from %CSP.Req/resp respectively

I build a tProxy with the fields I need for the post and set it %ToJson... I have tried seting %request.Content = tProxy (and not)

 

I call the method for the post url directly... 

  When that method calls %fromJson to set an object with the info. I passed... 

      - when I don't set %request.content.. I get a error '5035 - premature end of data code 12'

      - when I set %request.content=tProxy.. I get an errror Method Does not exist 

Any tips on what may be going on?

 

Last answer 19 February 2018
0   0 7
385

views

0

rating

Hello everyone,

i already asked this question in another post (https://community.intersystems.com/post/how-can-i-import-my-json-formatt...) and i'm sorry for creating a new post but i still didn't get an answer so i try it again. Now i know how to import my JSON formatted data from my API to my DocDB but now i have the problem that my JSON formatted data from my API is imported only to the %Doc  column and not to the columns that i created with my properties.  I'm not really sure but i think that the document database only puts my information from my API to the right columns if my JSON is in a JSONArrray format. But the format of my API is JSONObject and looks like this

Last answer 11 October 2018 Last comment 5 October 2018
0   0 2
486

views

0

rating

Hello everyone,

i want to create an iris document database with Atelier with some properties, where i can import my JSON formatted data from an API to the database which i created. Right now i know how to import my local JSON formatted data to my created database:

Class User.Classtest

Last answer 4 October 2018 Last comment 7 October 2018
0   0 2
292

views

0

rating

Hi everyone,

I need submit a object have a json string as property of class, but I get an issue, object can't save to SQL table if I take json data to json property. I try making a test class with only json property and get the same issue, no data row in SQL table after run ClassMethod . Some one know what's problem, please help me. Here my test class

Last answer 4 October 2018 Last comment 4 October 2018
+ 1   0 2
219

views

+ 1

rating

404 Not Found

{
"error": {
 "errors": [
  {
   "domain": "global",
   "reason": "notFound",
   "message": "Not Found"
  }
 ],
 "code": 404,
 "message": "Not Found"
 }
}

I want to do something like the above sample from a Google Storage JSON API. I have a call to Write obj.%ToJSON() followed by return ..ReportHttpStatusCode(..#HTTP404NOTFOUND) however the HTTP Status code is always 200.  If I remove the Write obj.%ToJSON() statement it returns a 404 status with no body. How do I return both?

Last answer 19 September 2018
0   0 3
0

comments

239

views

0

rating

Hi,

we have Angular solution and Cache server. We need to have separate users and sessions on same browser (laptop, table etc) for every user and for one user with many connections.

Thought this was resolved, but unfortunately not.

-----------------------------------------------------------------------------------------------------------------------

I got the code away from here, because it was some how ok.

The session on server mixed, but no any more, thanks our folk and local engineer's tools :)

We had some silly GROUP BY ID %ISCMgtPortal in WebApplication settings and even we had use session Cookie, IE added some cookie., but not any more after they took that setting away.

Last comment 4 September 2018
0   0 1
0

answers

171

views

0

rating

In a EnsLib.REST.Operation I have...

Set tSC=..Adapter.Post(.tHttpResponse,,pRequest.stream)

This sends JSON string over HTTP

I am getting this error back from the server

ErrHTTPStatus: Received non-OK status 415 from remote HTTP server: 'HTTP/1.1 415 Unsupported Media Type'

I have been told that the media type should be "JSON"

how do I go about changing the media-type of the HTTP Request?

Last answer 3 September 2018
0   0 2
0

comments

325

views

0

rating

I'm trying to have my REST service return the entire data set for one of our legacy globals.  Currently I am parsing the object from a SQL statement into generic objects to be returned like this:


         Set specimenArray=[]
        
        WHILE resultSet.%Next() {
            Set specimen = {}
            Set specimen.SpecimenId= resultSet.SpecimenId
            Set specimen.ProjectId = resultSet.ProjectId
            
            Set Oref = specimenArray.%Push(specimen)
        }
        
        Set tProxy = specimenArray.%ToJSON()
        set %response.Status = 200
        set %response.ContentType = "application/json"
        Set %response.CharSet="utf-8"

        Write tProxy

Last answer 23 July 2018 Last comment 23 July 2018
+ 1   0 2
210

views

+ 1

rating

Hi everyone,

I am still learning the platform for a student project and have to do some streaming and data analysis next. Since for my case I have no "live api" I wanted to just stream json files and output the data as it comes in from the files. (basically to emulate a incoming data scenario)

So thanks to the documentation and community posts I have figured how to create a stream and read data from a JSON but since I'm also new to JSON I have some parsing problems. I don't know how to access subarrays/sub-objects via objectscript.

The structure of the JSON File, I will omit some data because its large and the "rowset" has much more data

Last answer 3 July 2018 Last comment 4 July 2018
0   0 2
400

views

0

rating

Is it possible to produce a .json format using Ensemble 2015.2.2? Not sure what the trigger will be as of yet, but we have our local Department of Health trying to develop a reporting piece using .json. 

Not sure how this will work with our Ensemble instance not being in the DMZ to send outside our network, but I thought I would ask anyway to see if it is possible.

Thanks

Scott Roth

Last answer 17 May 2018
0   0 3
0

comments

157

views

0

rating