cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1740
Views
30
Helpful
11
Replies

JSON document in document repository?

Clifford McGlamry
Spotlight
Spotlight

I'm trying to do some development work, and did something I've done many times....put a sample data set into the document repository so I don't have to build a server side just for testing some stuff.  

 

But for the first time, I'm doing this with a JSON document.  File uploads just fine, but when I try to retrieve it from the repository in a script, the script engine throws and error saying "Source document variable "myDocument" is not a TextDocument.  

This variable contains the name of a file "Employees.txt".  That file contains the following simple JSON data:

 

{
"employees":
            {"first_name": "John",
             "last_name": "Doe"
             }
}

Since this is straight text, I'm not understanding why it cannot be retrieved from the repository.  Is this just some weird limitation of UCCX, or am I missing something?

 

Capture.JPG

.  

1 Accepted Solution

Accepted Solutions

Ok.....figured out how to do this.  This seems kind of a strange way to do this, but it works.  

Normally when pulling a document out of the repository, you drop it into a document variable.  That won't work if it's a JSON document.  What you have to do is drop it into a string variable instead.  You can then put the string variable into a document variable and proceed to work with it.  This is what worked for me below.  The variable types are self explanitory, but "myString" is a string, and "myDocument" is a document.  In watching the values in the variables in the debugger, you can see things populating correctly.  

 

Capture.JPG

View solution in original post

11 Replies 11

jim-j
Level 3
Level 3

Do you need to use a "Create File Document Step" first and then use that document object in the "Create JSON Document Step"?

I tried that too.....same error.  

Any difference in your text files that have worked in the past and the new json text files?  Encoding, line endings, etc.  Sorry, I haven't used JSON text files myself yet, but hope to in the future.  Hope you get this sorted out so I don't have to later. 

Ok.....figured out how to do this.  This seems kind of a strange way to do this, but it works.  

Normally when pulling a document out of the repository, you drop it into a document variable.  That won't work if it's a JSON document.  What you have to do is drop it into a string variable instead.  You can then put the string variable into a document variable and proceed to work with it.  This is what worked for me below.  The variable types are self explanitory, but "myString" is a string, and "myDocument" is a document.  In watching the values in the variables in the debugger, you can see things populating correctly.  

 

Capture.JPG

Thanks for sharing. Weird quirk, glad you figured it out, I doubt I would have.  I assume you could combine the first two lines like this:

Set myDocument = DOC[JsonTest.txt]

 

Nope.  That specifically does NOT work.  That's what lead to this entire thread.  

Hi Clifford, read this and I have progressed after days of frustration so thanks :-). Using your JSON txt as an example can you tell me what your JSONpath would be to extract the information on the Get JSON Document Data step?

My JSON is below 

[{
"StoreID": 12345,
"TelNo": "08765432123",
"Rang": "false",
"Acknowledged": "false"
}, {
"StoreID": 54321,
"TelNo": "12345678908",
"Rang": "false",
"Acknowledged": "false"
}, {
"StoreID": 908765,
"TelNo": "65465456484",
"Rang": "false",
"Acknowledged": "false"
}, {
"StoreID": 667543,
"TelNo": "6667765444",
"Rang": "false",
"Acknowledged": "false"
}]

I can't seem to get the JSON path correct to get e.g. StoreID e.g. $.[1].StoreID    (should be '54321').

Any help would be greatly appreciated.

 

Try using JSONPathFinder.com - you can paste your json string on the
left, and then select the portion you want to find the path to on the
right. It'll display the path expression. Looks like you have one too
many dots:
*$[0].StoreID or $[1].StoreID*

Hi, thanks for your response. I have used the JSONPathFinder previously (and jsonpath.herokuapp.com) and it worked but not on the UCCX when I was debugging. I eventually figured out what the issue was I and I am embarrassed to say that I did not have quotes around the StoreID (first one that I search on in UCCX script) data. Fixed that and it works. Thanks again for your response.
Best regards
Paul

$[1].StoreID is what will retrieve it.  You have an extra dot between the $ and the [.

 

You can paste your document into the online jayway jsonpath evaluator (this is the method UCCX uses) here and try it for yourself:  

 

https://jsonpath.herokuapp.com/

Hi, thanks for your response. I have used the jsonpath.herokuapp.com previously (and JSONPathFinder) and it worked but not on the UCCX when I was debugging. I eventually figured out what the issue was I and I am embarrassed to say that I did not have quotes around the StoreID (first one that I search on in UCCX script) data. Fixed that and it works.
Without your post on the CISCO Community regarding getting the JSON output to a string and then to a document I would have been lost on how to get it working! Its seems odd that after days of searching on how to get it working that there seems to be only your post!
Thanks again for your response.
Best regards
Paul
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: