Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to generate multiple xml files out of json's. #2

Open
digvijayah02 opened this issue Dec 7, 2019 · 4 comments
Open

Unable to generate multiple xml files out of json's. #2

digvijayah02 opened this issue Dec 7, 2019 · 4 comments

Comments

@digvijayah02
Copy link

digvijayah02 commented Dec 7, 2019

This utility is great for converting a single json but I am facing issue while trying to convert multiple json's.
I have a file which contains multiple json's. Every line is a json and I need to generate that many xml files.
Can you tell me what change would be required so that it reads a line converts that to a new XML file?

I have tried:-
OutputStream outputStream = new FileOutputStream("Path");
then use - new JsonStreamXMLWriter(reader, new BufferedWriter(new OutputStreamWriter(outputStream))).convert();

But it throws below error:-
Exception in thread "main" javax.json.stream.JsonParsingException: Expected EOF token, but got CURLYOPEN
at org.glassfish.json.JsonParserImpl.hasNext(JsonParserImpl.java:361)

Attached in the input json file.
input.txt
?

@namedgraph
Copy link
Member

namedgraph commented Dec 7, 2019

If I understand right, I think it would be easier to use shell utilities to read the text file line by line and feed each line into JSON2XML, like this:

#!/bin/bash

count=1
while IFS= read -r line; do
    echo "$line" | docker run -i -a stdin -a stdout -a stderr atomgraph/json2xml > "${count}.xml"
    count=$((count + 1))
done < "input.txt"

The script will produce XML files 1.xml, 2.xml etc, for each line of JSON.

Note that this requires a newline at the end of input.txt, otherwise the last line will not be read.

@digvijayah02
Copy link
Author

digvijayah02 commented Dec 7, 2019 via email

@namedgraph
Copy link
Member

What is the problem using your Splinterator then?

Alternatively, can you read each line into a byte array byte[] and construct a ByteArrayInputStream?

@digvijayah02
Copy link
Author

digvijayah02 commented Dec 9, 2019

I did some design changes and now getting single json in a single file. This way I would avoid EOF issue and also filename issue.
I am now able to read json files one by one and convert and create xml files.
But after doing that 1 successfull time, it is failing in between with below error:-
Exception in thread "main" javax.json.stream.JsonParsingException: Unexpected char 0 at (line no=1, column no=1, offset=0)
at org.glassfish.json.JsonTokenizer.unexpectedChar(JsonTokenizer.java:601)
at org.glassfish.json.JsonTokenizer.nextToken(JsonTokenizer.java:418)
at org.glassfish.json.JsonParserImpl$NoneContext.getNextEvent(JsonParserImpl.java:426)
at org.glassfish.json.JsonParserImpl.next(JsonParserImpl.java:376)
at com.dj.gls.json2xml.JsonStreamXMLWriter.write(JsonStreamXMLWriter.java:142)

Do you have any idea why it might be throwing that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants